如何使用Matplotlib的可读图中的数千个依赖日期的数据点格式化?
我有两个相应的列表,其中一个日期和另一个价格。列表长30,000个数据点。
x = [datetime.date(1997, 8, 8), datetime.date(2021, 8, 17), datetime.date(2019, 8, 7), ... ]
y = [0.49, 1.99, 0.0, ...]
我正在使用此代码生成以下图表:
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y/%m/%d'))
plt.gca().xaxis.set_major_locator(mdates.DayLocator(interval=5))
plt.scatter(x,y)
plt.gcf().autofmt_xdate()
plt.show()
我也不确定是否有可能使图形更可读性,或者这是具有如此多数据点的散点的本质(不确定还有什么使用)。
日期从1997年到2022年不等,价格从0.0(免费)到300。
此外,我遇到的错误即使在图表显示的时候也会不断弹出,我不知道它在做什么:
试图生成1995 tick的定位器([9591.0,...,19561.0]),它超过了定位器。
I have two corresponding lists, one of the dates and another of its respective price. The lists are 30,000 data points long.
x = [datetime.date(1997, 8, 8), datetime.date(2021, 8, 17), datetime.date(2019, 8, 7), ... ]
y = [0.49, 1.99, 0.0, ...]
I'm using this code to generate the graph below:
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y/%m/%d'))
plt.gca().xaxis.set_major_locator(mdates.DayLocator(interval=5))
plt.scatter(x,y)
plt.gcf().autofmt_xdate()
plt.show()
I'm supposed to have the dates separated in a readable format using the code above but it doesn't seem to work. I'm also not sure if it's possible to make the graph more readable or if that's the nature of a scatter with so many data points (not sure what else to use).
The dates range from 1997 to 2022 and the prices from 0.0 (free) to 300.
Also, I'm getting this error that constantly pops up even while the graph is showing and I have no idea what it's doing:
Locator attempting to generate 1995 ticks ([9591.0, ..., 19561.0]), which exceeds Locator.MAXTICKS (1000).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望图形更可读取,则需要将
日常
对象的间隔增加到至少6000。代码>scation
函数的参数:输出:
If you want your graph to be more readable, you need to increase the interval of
DayLocator
object to at least 6000. Also, you can change the size of the scatter points with thes
parameter at thescatter
function:Output: