pythonlistmatplotlibstatisticsscatter

Make a Scatter Plot in matplotlib with dates on x axis and values on y


I am having trouble making a scatter plot that has from a date array and a bunch of PM 2.5 values. My lists would look like the following:

dates = ['2015-12-20','2015-09-12']  
PM_25 = [80, 55]

Solution

  • import pandas as pd
    dates = ['2015-12-20','2015-09-12']  
    PM_25 = [80, 55]
    dates = [pd.to_datetime(d) for d in dates]
    
    plt.scatter(dates, PM_25, s =100, c = 'red')
    

    s sets the size c sets the color

    There are a whole bunch of other args as well: http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.scatter