Добавление информации по графику получено правильно - PullRequest
0 голосов
/ 25 апреля 2019

Мне удалось запустить функцию «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 (...) чтобы я мог отображать новые данные на том же графике?)

Спасибо!

1 Ответ

0 голосов
/ 26 апреля 2019

Конечно, DavidG. В очередной раз благодарим за помощь. Надеюсь увидеть вас в других постах.

Заинтересованные читатели смогут адаптировать этот «реальный материал» ниже (он работает)!

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...