繁体   English   中英

python matplotlib - 检索 xaxis_major_locator 作为时间值

[英]python matplotlib - retrieve xaxis_major_locator as time value

我正在使用 matplotlib 绘制时间序列(时间序列如下所示): 在此处输入图片说明

我使用的部分代码在每天凌晨 0 点设置主要定位器:

fig, ax = plt.subplots(figsize=(20, 3))
mpf.candlestick_ohlc(ax,quotes, width=0.01)
ax.xaxis_date()
ax.xaxis.set_major_locator(mpl.dates.DayLocator(interval=1) )

我想在每天下午 16 点到早上 8 点之间在图表上绘制较暗的背景,并计划使用axvspan来完成该任务。 考虑到 axvspan 将axvspan(xmin, xmax)作为参数axvspan(xmin, xmax)我想知道是否可以将xaxis_major_locator 作为 ax 值进行检索,以便将其作为axvspan(xmin=major_locator-3600s, xmax=major_locator+3600s)传递给 axvspan

编辑:我在文档中找到了这个函数: http : //matplotlib.org/2.0.0rc2/api/ticker_api.html#matplotlib.ticker.Locator

如果有人知道如何从 Xaxis_major 返回股票位置列表,请告诉我。 谢谢。

Edit2:如果我使用print(ax.xaxis.get_major_locator())我收到作为返回<matplotlib.dates.DayLocator object at 0x7f70f3b34090>我如何从中提取刻度位置列表?

好的找到了... Majors=ax.xaxis.get_majorticklocs()

暂无
暂无

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

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