0

我能够使用以下(仅相关的)代码运行“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(...) 的内容,以便能够使新数据出现在同一个图表中?)

谢谢!

4

1 回答 1

0

当然,大卫G。再次感谢你的帮助。希望在其他帖子中见到你。

感兴趣的读者将能够在下面改编这个“真实的东西”(它正在工作)!

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

于 2019-04-26T15:02:00.990 回答