![](/img/trans.png)
[英]Wrong values appears… using python matplotlib.ticker (ax.xaxis.set_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.