python matplotlib检索xaxis\u major\u定位器作为时间值

2024-05-19 12:34:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用matplotlib绘制一个timeserie(timeserie如下所示): enter image description here

我使用的部分代码设置了每天凌晨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)作为参数,我想知道是否有可能检索xaxis\u major\u定位器作为x值,以便将其作为axvspan(xmin=major_locator-3600s, xmax=major_locator+3600s)传递给axvspan

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

如果有人知道如何返回一个从Xaxisèu主要股票位置列表,让我知道。谢谢

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


Tags: api列表matplotlibaxtickerdatesxminlocator