我的代码是:
fig = make_subplots(rows = 1, cols = 1, shared_xaxes = True, subplot_titles =
(currency_name+' '+timeframe), vertical_spacing = 0.1, row_width = [0.6])
# ----------------
# Candlestick Plot
fig.add_trace(go.Candlestick(x = chart.index, open = chart['open'], high =
chart['high'], low = chart['low'], close = chart['close'], showlegend=False, name =
'candlestick'), row = 1, col = 1)
# Moving Average
fig.add_trace(go.Scatter(x = chart.index, y = chart['middle_band'], line_color =
'green', name = 'middle_band', opacity = 0.5), row = 1, col = 1)
# Upper Bound
fig.add_trace(go.Scatter(x = chart.index, y = chart['upper_band'], line_color =
'green', name = 'upper band', opacity = 0.7), row = 1, col = 1)
# Lower Bound
fig.add_trace(go.Line(x = chart.index, y = chart['lower_band'], line_color = 'green',
name = 'lower band', opacity = 0.7), row = 1, col = 1)
fig.update_layout(
title='Bolindger Bands',
yaxis_title=currency[5]+' '+timeframe,
shapes = [dict(
x0=chart.index[0].to_pydatetime(), x1=chart.index[0].to_pydatetime(), y0=0.1,
y1=0.2, xref='x', yref='paper',
line_width=1)],
annotations=[dict(
x=chart.index[0].to_pydatetime(), y=0.01, xref='x', yref='paper',
showarrow=False, xanchor='right', text=str(candle_pattern)+ ' here')])
# Remove range slider; (short time frame)
fig.update(layout_xaxis_rangeslider_visible=False)
fig.show()
我得到了带有烛台和指标的漂亮图片,但我找不到如何将其保存为 png 的方法?
fig.savefig() 不适用于 make_subplots。如何将我在 fig.show() 之后得到的那张图片准确地保存到 png 中?