user297850
user297850

Reputation: 8015

plot time series dataframe and mark certain points using pandas and 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?

enter image description here

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

enter image description here

Upvotes: 1

Views: 783

Answers (1)

Yuca
Yuca

Reputation: 6091

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')

Upvotes: 1

Related Questions