【问题标题】:An additional line in timeseries plot with Matplotlib使用 Matplotlib 的时间序列图中的附加线
【发布时间】:2021-08-24 22:52:54
【问题描述】:

我有一个不同车站的交通流量数据集。

我试图只在夏天这样的有限时间内绘制它们。当我绘图时,我可以看到有一条线穿过每个绘图中的所有绘图。

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

【问题讨论】:

  • 我添加了数据快照
  • 谢谢,我对索引进行了排序,它成功了。

标签: python matplotlib time-series


【解决方案1】:

正如 John Hennig 在 cmets 中建议的那样,我只是在情节之前订购了索引,并且它起作用了。

gdf = gdf.sort_index()

【讨论】:

    猜你喜欢
    • 2018-04-02
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    • 1970-01-01
    相关资源
    最近更新 更多