error on bar chart (Python, Matplotlib)
Question: code for ploting bar chart:

    
    
    import pylab as pl
    
    
    data = """35389 6
    35316 7
    33921 8
    1914 5
    21 4
    3 3
    3 2
    """
    
    values = []
    dates = []
    
    for line in data.split("\n"):
        x, y = line.split()
        values.append(int(x))
        dates.append(int(y))
    
    fig = pl.figure()
    ax = pl.subplot(111)
    ax.bar(dates, values, width=100)
    ax.xaxis_date()
    

Give this error :

File "try2.py", line 17, in x, y = line.split() ValueError: need more than 0
values to unpack

How to fix it?


Answer: I have slightly re-written some of your original code namely the string as the
putting `"""` at the bottom like you have it will cause a redundant new
element to be added to the list since you are splitting upon a new line

You have created the plot, but you still have not shown the plot I have fixed
this by adding two additional lines to the bottom of your code. However, even
with this you are going to have one or two more errors and I will leave these
to you to figure out the resolution.

    
    
    import pylab as pl
    
    data = """35389 6
    35316 7
    33921 8 
    1914 5
    21 4
    3 3
    3 2"""
    
    values = []
    dates = []
    
    for element in data.split("\n"):
        x, y= element.split()
        values.append(int(x))
        dates.append(int(y))
    
    fig = pl.figure()
    ax = pl.subplot(111)
    ax.bar(dates, values, width=100)
    ax.xaxis_date()
    fig.show()
    pl.show()
    

