Making Fill Plot Matplotlib - Error: invalid type promotion
Question: I am trying to create a fill plot using Matplotlib in Python (I am using
spyder IDE) using the code below. However, I receive the error posted at the
bottom of the code. The dataframe I want to plot contains dates along the
x-axis and then a range of y-values (I created the sample dataframe to see if
the error was reproduced, in case there was a problem with my dataframe).

This seems to be snagging me quite a bit and I am trying to start from scratch
(and visited the matplotlib website, which is posted in the comments within
the codes).

I am very new to Python and Matplotlib and maybe I am just missing something
basic. I will bee needing to add a lot of plots with date-time x-axis for the
work I am performing, so if there are any additional features I should be
aware of, please let me know as it would be greatly appreciated!

Thanks in advance!

    
    
    import pandas as pd
    import numpy as np
    import datetime as dt
    import matplotlib.pyplot as plt
    
    data1 = [{'a':dt.datetime(2015,1,1,12,0,0), 'b':1},{'a':dt.datetime(2015,1,1,13,0,0), 'b':2},{'a':dt.datetime(2015,1,1,14,0,0), 'b':3}]
    df1 = pd.DataFrame(data1)
    
    data2 = [{'a':dt.datetime(2015,1,1,12,0,0), 'c':9},{'a':dt.datetime(2015,1,1,13,0,0), 'c':8},{'a':dt.datetime(2015,1,1,14,0,0), 'c':7}]
    df2 = pd.DataFrame(data2)
    
    df3 = pd.merge(df1, df2, how = 'left', on = 'a')
    
    plt.fill(df3['a'], df3['c'])
    plt.show()
    
    """
    used this example code from Fill Demo on page http://matplotlib.org/users/screenshots.html
    import numpy as np
    import matplotlib.pyplot as plt
    
    
    x = np.linspace(0, 1)
    y = np.sin(4 * np.pi * x) * np.exp(-5 * x)
    
    plt.fill(x, y, 'r')
    plt.grid(True)
    plt.show()
    """
    
      File "/Applications/anaconda/lib/python3.5/site-packages/numpy/core/shape_base.py", line 280, in hstack
        return _nx.concatenate(arrs, 1)
    
    TypeError: invalid type promotion
    


Answer: Just use the values instead of the Series directly:

    
    
    plt.fill(df3['a'].values, df3['c'].values
    

You more likely want this type of plot:

    
    
    plt.fill_between(df3['a'].values, df3['c'].values)
    

