0

My code is:

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()

And I got nice picture with candlesticks and indicators, but I cant find the way how to save it to png?

fig.savefig() doesnt work with make_subplots. How to save exactly that picture which I got after fig.show() to png?

Timur
  • 11
  • Have you tried `matplotlib.pyplot.savefig`? – Brad Campbell Jan 07 '22 at 18:17
  • of course I tried. fig.savefig() doesnt work with make_subplots. Or I use it wrong. matplotlib.pyplot.savefig works only when fig = plt.figure(figsize=(3, 6)) and so on. In my case fig = make_subplots and after a lot of add_trace. – Timur Jan 10 '22 at 12:22
  • If you haven't solved this yet, can you make a small, runnable code sample (including import statements and sample data)? That's what is needed to really help. – Brad Campbell Feb 11 '22 at 14:40

0 Answers0