I have the following time series with ts
as index and column named metric_value
:
ts
2020-01-01 00:00:00 1225917
2020-01-01 01:00:00 670334
2020-01-01 02:00:00 668207
2020-01-01 03:00:00 576977
2020-01-01 04:00:00 713490
Name: metric_value, dtype: int32
I'm trying to plot this time series and mark the outlier data points with a red circle. The outliers' indexes are in this list:
idxs=['2020-06-06 19:00:00', '2020-07-04 19:00:00', '2020-08-08 19:00:00']
The following shows how I'm plotting the data for June.
fig, ax = plt.subplots(1, 1, sharex="all", sharey="all", figsize=(12,4))
ax = ts.loc['2020-06-01 00:00:00':'2020-06-30 23:00:00']['metric_value'].plot(title='June')
ax = ts.loc[[idx for idx in idxs if idx>'2020-06-01 00:00:00' and idx<'2020-06-30 23:00:00']]['metric_value'].plot(style='.')
plt.xticks(rotation=45)
plt.ylim(bottom=0)
For month June, there is one outlier at this index=2020-06-06 19:00:00
. The issue is that the plot doesn't show this data point on the correct location. It shows it on the first location which is zero! I think it happens because these two plots are not sharing the x-axis and as the plot shows only the second plots' axis. How can I fix it?
I tried this solution but it didn't work!