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

随声附和 提交于 2019-12-01 17:09:09
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

If a plot with data that contains dates, you can use plot_date

Similar to the plot() command, except the x or y (or both) data is considered to be dates, and the axis is labeled.

First convert list to date time, as @RSHARP showed,

dates = [pd.to_datetime(d) for d in dates]

then you can use plot_date

plt.plot_date(dates, PM_25, c = 'red')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!