plot time series dataframe and mark certain points using pandas and matplotlib

五迷三道 提交于 2021-01-29 04:11:10

问题


I have a dataframe storing a time series, which looks like as follows. How to plot it using time column as x-axis. Moreover, if I want to mark certain points between a given time period, e.g., 2014-11-18 to 2015-1-30. How to do that using matplotlib?

This is what I did, but it appears pretty small, and how to add some marks over the certain time period?


回答1:


the easiest way to do this is to plot twice, the second plot having the extra style. Regarding the plot size, you can control the figsize parameter. Just set a tuple with the height and width you like

# make sure index is in datetime format
df_id_ts.index = pd.to_datetime(df_id_ts.index, figsize=(10,6))
ax = df_id_ts.plot()
df_id_ts['2014-11-18' : '2015-01-30'].plot(ax = ax, marker = 'ro')


来源:https://stackoverflow.com/questions/51826132/plot-time-series-dataframe-and-mark-certain-points-using-pandas-and-matplotlib

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