如何在X轴上显示所有日期值?

2024-09-30 01:26:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我在x轴上有以下日期,图表并没有显示所有值。我需要什么设置来显示所有的x值?在

drray2 ['2019-04-23', '2019-04-25', '2019-04-29', '2019-04-30', '2019-05-01', '2019-05-02', '2019-05-06', '2019-05-13', '2019-05-15', '2019-05-16', '2019-05-20', '2019-05-23', '2019-05-24', '2019-05-28', '2019-06-11', '2019-06-12', '2019-06-14']
countarray2 [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 3, 1]

p1=plt.bar(converted_dates_2,countarray2,color="Green", width=barWidth,label="second load")
plt.show()

Tags: 图表barloadpltgreenwidthlabelcolor
2条回答

对于x轴,可以使用频率1作为

ax.xaxis.set_major_locator(dates.DayLocator(interval=1))

使用您之前给出的代码完成答案

^{pr2}$

enter image description here

我不太清楚为什么它没有为您显示,我用xticks属性在本地运行它: 代码:

x = ['2019-04-23', '2019-04-25', '2019-04-29', '2019-04-30', '2019-05-01', '2019-05-02', '2019-05-06', '2019-05-13', '2019-05-15', '2019-05-16', '2019-05-20', '2019-05-23', '2019-05-24', '2019-05-28', '2019-06-11', '2019-06-12', '2019-06-14']
y = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 3, 1]
plt.bar(x,y,color="Green")
plt.xticks(rotation=90)
plt.show()

图表是:

Final Plot

相关问题 更多 >

    热门问题