在正确获取的图形上添加信息

2024-06-26 14:26:21 发布

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

我能够运行“mpl_finance”candlestick_ohlc函数,使用以下(仅相关)代码,图形显示如预期:


mondays = WeekdayLocator(MONDAY)        # major ticks on the mondays
alldays = DayLocator()              # minor ticks on the days
weekFormatter = DateFormatter('%b %d')  # e.g., Jan 12
dayFormatter = DateFormatter('%d')      # e.g., 12

fig, ax = plt.subplots()
fig.subplots_adjust(bottom=0.2)
ax.xaxis.set_major_locator(mondays)
ax.xaxis.set_minor_locator(alldays)
ax.xaxis.set_major_formatter(weekFormatter)

candlestick_ohlc(ax, zip(mdates.date2num(quotes.index.to_pydatetime()),
                         quotes['open'], quotes['high'],
                         quotes['low'], quotes['close']),
                 width=0.6)

ax.xaxis_date()
ax.autoscale_view()
plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')
plt.title('PETR4 daily quotes')
plt.show() 

现在我想在这张图上加一条y=26.5的水平红线。。。我应该如何进行

(我真正的问题是:我应该如何/在哪里键入类似axvline(…)的内容,以便能够在同一个图表中显示新数据?)

谢谢


Tags: theonpltaxquotessetminorohlc
1条回答
网友
1楼 · 发布于 2024-06-26 14:26:21

当然,大卫。再次感谢你的帮助。希望在其他职位上看到你

感兴趣的读者将能够适应下面的“真实内容”(它正在工作)

mondays = WeekdayLocator(MONDAY)        # major ticks on the mondays
alldays = DayLocator()              # minor ticks on the days
weekFormatter = DateFormatter('%b %d')  # e.g., Jan 12
dayFormatter = DateFormatter('%d')      # e.g., 12

fig, aux = plt.subplots()
fig.subplots_adjust(bottom=0.2)
aux.xaxis.set_major_locator(mondays)
aux.xaxis.set_minor_locator(alldays)
aux.xaxis.set_major_formatter(weekFormatter)

candlestick_ohlc(aux, zip(mdates.date2num(quotes.index.to_pydatetime()),
                         quotes['open'], quotes['high'],
                         quotes['low'], quotes['close']),
                 width=0.6)

for i in range(len(features_period.date)):
    plt.plot(quotes.index, quotes.close , 'd', color='blue')

aux.xaxis_date()
aux.autoscale_view()
plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')
plt.title('USIM5 daily quotes')

plt.rcParams['figure.figsize'] = [10, 10]

display(candlestick_ohlc);

(蓝色圆点被添加到使用/提及的模块创建的图形中。)

问候,, fskilnik

相关问题 更多 >