【发布时间】: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 标签。在不改变情节的情况下,如何按周而不是按天进行标记?
【问题讨论】:
-
我找到了以下解决方案stackoverflow.com/a/46343722/12934163:
n = 7 # Keeps every 7th label [l.set_visible(False) for (i,l) in enumerate(ax.xaxis.get_ticklabels()) if i % n != 0]
标签: python pandas matplotlib