Write_image seems to change color of figure

Iโ€™m storing figures as .png and canโ€™t figure out why the colors seem to change.

My full current code :


def dataplotter(stock, date):
    # Create subplots and set plot grid size
    fig = make_subplots(rows=2, cols=1, shared_xaxes=True, 
                   vertical_spacing=0.01, subplot_titles=(f'{stock}', ''), 
                   row_width=[0.2, 0.7])

    fig.add_trace(go.Candlestick(x=df['Time'],
                        open=df['Open'],
                        high=df['High'],
                        low=df['Low'],
                        close=df['Close'],
                                increasing_line_color= '#2196F3', decreasing_line_color= '#000000',
                                increasing_fillcolor= '#2196F3', decreasing_fillcolor= '#000000' ))

    fig.update_layout(height=900,
                        paper_bgcolor='rgba(000,000,000,0)', # Background outside
                        plot_bgcolor='rgba(0,0,0,0)')

    # Remove rangeslider + set hovermode (crosshair)
    fig.update_layout(xaxis_rangeslider_visible=False, hovermode='x unified')

    fig.update_yaxes(ticks="outside", tickwidth=1, tickcolor='grey', ticklen=10, col=1)

    # Add volume data in subplot
    fig.add_trace(go.Bar(x=df.Time, y=df.Volume, yaxis='y2'))

    fig.update_yaxes(gridcolor='rgba(211,211,211,211)', gridwidth=0.1, showspikes=True, spikedash='dot', spikemode='across', 
                    spikecolor="black",spikesnap="cursor",spikethickness=1)

    #fig.update_xaxes(showline=True, linewidth=2, linecolor='black')
    fig.update_yaxes(showline=True, linewidth=2, linecolor='black')
    
    fig.add_vline(x="2023-01-25 14:30:00+00:00", line_color='grey', line_dash="dash")
    
    fig.show()

    #Storage
    time_string = datetime.datetime.now().strftime('%Y-%m-%d %H.%M')
    filename = stock + ' ' + time_string + '.png'
    print(filename)
    fig.write_image(filename, scale=6, width=1920, height=1080)
    
dataplotter("SNOA", "2023-01-25")

Rendering in Jupyter Notebook looks like this:

While my exported image looks like this:

Hi, I have never observed this. How did you create the chart in your jupyter notebook?

1 Like

Hi, just added the full code now in my post. Avoided that before as it seemed long.

UPDATE:
Turns out I was using 0,0,0 for RGBA white, where I should have used 255,255,255.
So I guess it had no color - which defaults to the background and that happened to be white in my jupyter notebook and black in a .png file.

Glad you figured it out. rgba strings are defined with four values:

rgba(0,0,0,0)

red
green
blue
alpha

2 Likes