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

前端 未结 3 893
予麋鹿
予麋鹿 2020-12-06 18:50

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-         


        
3条回答
  •  攒了一身酷
    2020-12-06 19:11

    a pandas dataframe is more common usually. so it's efficient to me:

    import pandas as pd
    dates = ['2015-12-20','2015-09-12']  
    PM_25 = [80, 55]
    data = pd.DataFrame({'dates':pd.to_datetime(dates),'PM_25':PM_25})
    data.plot(x='dates',y='PM_25',marker='o',linestyle='none')
    

    and you can define more like this:

    data.plot(x='dates',y='PM_25',marker='o',linestyle='none',color='red',ms=3)
    

提交回复
热议问题