每个日期都太接近
我有一个简单的图表,显示了一段时间内的比特币价格,正如您在图片中看到的那样。
问题是 x 轴上的日期彼此太接近。问题是我不需要显示每一个日期。我可以以某种方式将它们限制为 6 个标签,而不是您现在在图像上看到的 25 个标签吗?或者有没有更好的方法来处理日期?
我的代码:
def plot_data_out(x: array, y: array):
x = np.array(x,dtype=datetime)
y = np.array(y,dtype=float)
print(x)
print(y)
plt.plot(x, y)
plt.show()
x数据:
['2022-03-04 01:00:00' '2022-03-04 02:00:00' '2022-03-04 03:00:00'
'2022-03-04 04:00:00' '2022-03-04 05:00:00' '2022-03-04 06:00:00'
'2022-03-04 07:00:00' '2022-03-04 08:00:00' '2022-03-04 09:00:00'
'2022-03-04 10:00:00' '2022-03-04 11:00:00' '2022-03-04 12:00:00'
'2022-03-04 13:00:00' '2022-03-04 14:00:00' '2022-03-04 15:00:00'
'2022-03-04 16:00:00' '2022-03-04 17:00:00' '2022-03-04 18:00:00'
'2022-03-04 19:00:00' '2022-03-04 20:00:00' '2022-03-04 21:00:00'
'2022-03-04 22:00:00' '2022-03-04 23:00:00' '2022-03-05 00:00:00'
'2022-03-05 01:00:00']
y数据
[42454. 41603.36 41510.58 41403.7 41449.93 41379.99 41374.45 41407.98
41436.98 41590. 41522.29 41676.56 41662.06 41511.3 41315.75 41106.91
40694.32 40754.41 40840.53 40605.88 39782.13 39469.36 39392.83 39004.73
39148.65]
I have simple graph showing bitcoin price in some time as you can see on image.
Problem is that on x axis there are dates too close to each other. Thing is that I dont need to show every one date. Can I somehow limit them to lets say 6 labels instead of 25 as you can see on image right now. Or is there any better way how to handle dates?
My code:
def plot_data_out(x: array, y: array):
x = np.array(x,dtype=datetime)
y = np.array(y,dtype=float)
print(x)
print(y)
plt.plot(x, y)
plt.show()
x data:
['2022-03-04 01:00:00' '2022-03-04 02:00:00' '2022-03-04 03:00:00'
'2022-03-04 04:00:00' '2022-03-04 05:00:00' '2022-03-04 06:00:00'
'2022-03-04 07:00:00' '2022-03-04 08:00:00' '2022-03-04 09:00:00'
'2022-03-04 10:00:00' '2022-03-04 11:00:00' '2022-03-04 12:00:00'
'2022-03-04 13:00:00' '2022-03-04 14:00:00' '2022-03-04 15:00:00'
'2022-03-04 16:00:00' '2022-03-04 17:00:00' '2022-03-04 18:00:00'
'2022-03-04 19:00:00' '2022-03-04 20:00:00' '2022-03-04 21:00:00'
'2022-03-04 22:00:00' '2022-03-04 23:00:00' '2022-03-05 00:00:00'
'2022-03-05 01:00:00']
y data
[42454. 41603.36 41510.58 41403.7 41449.93 41379.99 41374.45 41407.98
41436.98 41590. 41522.29 41676.56 41662.06 41511.3 41315.75 41106.91
40694.32 40754.41 40840.53 40605.88 39782.13 39469.36 39392.83 39004.73
39148.65]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 x 轴数据转换为日期时间格式,然后用它来绘制图表。即使这样,您也可以看到标签看起来很拥挤。您可以将标签旋转 30 度并获得更清晰的图表
You can convert the x axis data to datetime format and then use it to plot the graph. Even then you can see the labels look congested. You can rotate the labels by 30 degrees and have more legible chart