python怎样将日期转为x轴,如何使用python在matplotlib中更改x轴值的日期时间格式?...

本文探讨了如何优化Python matplotlib图表中日期x轴的显示,目标是仅展示部分日期值,并调整日期时间格式。尝试使用`plt.xticks(rotation=70)`未能解决问题,现在寻求将日期格式化为'MMM DD'或'DD MMM',甚至考虑两行显示'DD MM YYYY'。提供的代码示例展示了如何创建图表,并给出了包含日期时间戳和价格的数据。解决方案涉及设置日期的格式,使用`mdates.DateFormatter('%d %m')`来改变x轴日期显示。
摘要由CSDN通过智能技术生成

How can I make this plot's x-axis looks better?

Is there any way to show only 3 values in x-axis while plotting all values in my dataframe?

Zxy7W.png

I tried using plt.xticks(rotation=70) but it still cuts my numbers..

As you can see, it shows the date in the format MMM DD YYYY.

I wanna something like MMM DD or DD MMM. Or even writing in 2

lines DD MM \n YYYY.

How can I achieve that?

This is the code used for generating the chart:

plt.plot(df_21d["Timestamp"], df_21d["Close"], label="Price", color="b")

plt.title("BTC - 21 Dias")

plt.xlabel("Data")

plt.ylabel("Preco (em USD)")

plt.grid(True)

plt.show()

Here's my data:

df_

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值