【问题标题】:Editing densely packed x labels in timeseries在时间序列中编辑密集的 x 标签
【发布时间】:2020-05-06 11:12:59
【问题描述】:

我有以下代码可以生成一个情节。

labels = sorted(set(df.index))
a = df.loc[df.user_id ==1234, 'count']
b = df.loc[df.user_id ==5678, 'count']
width = 0.5
x = np.arange(len(labels))  # the label locations


fig, ax = plt.subplots(figsize=(10,5))
rects1 = plt.plot_date(x, a, width, label='a')
rects2 = plt.plot_date(x, b, width, label='b', color = 'orange')

ax.set_xticks(x)
ax.set_xticklabels(labels, rotation=90)
ax.legend(['a','b'])
plt.ylabel('counts')

fig.tight_layout()
plt.gcf().autofmt_xdate()
plt.show()

明显的问题是无法读取密集的 x 标签。在不改变情节的情况下,如何按周而不是按天进行标记?

【问题讨论】:

标签: python pandas matplotlib


【解决方案1】:
plt.xticks(range(0,len(label), 7), label[::7])

根据每日数据,该节目每 7 天更新一次

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-12
    • 1970-01-01
    • 2022-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多