An additional line in timeseries plot with Matplotlib

Viewed 45

I have a dataset of traffic flow for different stations. enter image description here

I am trying to plot them only for a limited time like summer. When I plot, I can see there is a line crossing all the plot in each of them.

fig, ax = plt.subplots(nrows=16, figsize=(60,120))

stations = countData19_gdf['address'].unique()
print(len(stations))
summersubset = countData19_gdf.loc['2019-06-01': '2019-08-31']
cnt=0
for station in stations:
    station_data = summersubset[summersubset['address'] == station]
    ax[cnt].plot( station_data['volume'], c='green',  label= 'flow')
    ax[cnt].title.set_text(station)
    ax[cnt].set_xlabel('Study Date')
    ax[cnt].set_ylabel('volume (V/15 minutes)')
    ax[cnt].set_title(station)
    ax[cnt].grid(True)
    ax[cnt].xaxis.set_major_locator(DayLocator())
    ax[cnt].xaxis.set_major_formatter(DateFormatter('%m/%d'))
    ax[cnt].legend(loc='upper left')

    cnt = cnt +1

enter image description here

1 Answers

As John Hennig suggested in the comments, I just ordered the index before the plot, and it worked.

gdf = gdf.sort_index()
Related