如何在金融 Matplotlib Python 图中跳过空日期(周末)? [英] How to skip empty dates (weekends) in a financial Matplotlib Python graph?

查看:49
本文介绍了如何在金融 Matplotlib Python 图中跳过空日期(周末)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ax.plot_date((dates, dates), (highs, lows), '-')

我目前正在使用此命令使用 Matplotlib 绘制财务高点和低点.效果很好,但是如何去除没有市场数据的天数(例如周末和节假日)在 x 轴上留下的空白?

I'm currently using this command to plot financial highs and lows using Matplotlib. It works great, but how do I remove the blank spaces in the x-axis left by days without market data, such as weekends and holidays?

我有日期、最高价、最低价、收盘价和开盘价的列表.我找不到任何使用 x 轴显示日期但不强制执行恒定比例的图表的示例.

I have lists of dates, highs, lows, closes and opens. I can't find any examples of creating a graph with an x-axis that show dates but doesn't enforce a constant scale.

推荐答案

我认为您需要通过使用 xticks 将刻度标签设置为表示日期的字符串(当然,即使您表示的日期不是等距的,也以等距的间隔放置刻度),然后使用普通的 plot.

I think you need to "artificially synthesize" the exact form of plot you want by using xticks to set the tick labels to the strings representing the dates (of course placing the ticks at equispaced intervals even though the dates you're representing aren't equispaced) and then using a plain plot.

这篇关于如何在金融 Matplotlib Python 图中跳过空日期(周末)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆