简体   繁体   English

烛台图上的Matplotlib半小时主要定位器

[英]Matplotlib half hour major locator on candlestick chart

I'm attempting to draw a candlestick chart with historical data for every half hour, therefore using a major locator for every 30 minutes and have a minor locator of 10 min. 我试图绘制每半小时具有历史数据的烛台图表,因此每30分钟使用一个主要定位器,而次要定位器为10分钟。 How can I achieve a half-hour major locator? 如何获得半小时的主要定位器?

I currently have a HourLocator but I would like to add some extensibility by being able to create locators for custom times, example: for every 45 minutes or a major locator for every 10 minutes. 我目前有一个HourLocator但是我想通过能够为自定义时间创建定位器来增加一些可扩展性,例如:每45分钟创建一个定位器,或者每10分钟创建一个主要定位器。

This is why I currently have: 这就是为什么我现在有:

halfHourFormatter = DateFormatter('%d %H:%M:%S')

date1 = date2num(datetime.datetime.strptime("17/03/2016 22:30:00", "%d/%m/%Y %H:%M:%S"))
date2 = date2num(datetime.datetime.strptime("17/03/2016 23:00:00", "%d/%m/%Y %H:%M:%S"))

quotes = [
    (date1,86.439,86.574,86.423,86.545),
    (date2,86.545,86.551,86.019,86.024)
]

fig, ax = plt.subplots()
fig.subplots_adjust(bottom=0.2)
ax.xaxis.set_major_locator(dates.HourLocator()) # Ideally: 30 Minute locator
ax.xaxis.set_major_formatter(halfHourFormatter)
ax.xaxis.set_minor_locator(<10 MINUTE LOCATOR>)

candlestick_ohlc(ax, quotes, width=0.006,colorup='g', colordown='r')

ax.xaxis_date()
ax.autoscale_view()
plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')

plt.show()

Additional question: Is there a way to set the width of the candlestick flag based on the time of the data? 附加问题:是否有一种方法可以根据数据时间设置烛台标志的宽度? In this case, a width of 0.006 seems to work for a 30-minute tick and 0.6 for a day-tick. 在这种情况下,0.0030的宽度似乎适用于30分钟的刻度,而0.6的宽度适用于一日的刻度。

Thanks! 谢谢!

Have you tried: 你有没有尝试过:

dates.MinuteLocator(interval=30)

From the docs to dates.MinuteLocator : 文档dates.MinuteLocator

interval is the interval between each iteration. interval是每次迭代之间的间隔。 For example, if interval=2 , mark every second occurrence. 例如,如果interval=2 ,则标记第二次出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM