绘制时间序列数据帧并使用pandas和matplotlib标记某些点 [英] plot time series dataframe and mark certain points using pandas and matplotlib
问题描述
我有一个存储时间序列的数据框,如下所示.如何使用时间列作为 x轴
进行绘制.此外,如果我想标记给定时间段之间的某些点,例如 2014-11-18
到 2015-1-30
.如何使用 matplotlib
来做到这一点?
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?
推荐答案
最简单的方法是绘制两次,第二个具有额外的样式.关于绘图大小,您可以控制 figsize
参数.只需设置一个你喜欢的高度和宽度的元组
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')
这篇关于绘制时间序列数据帧并使用pandas和matplotlib标记某些点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!