Why is it so hard to fins information for plotly graph objects!

Hey All ,

Excuse the frustration. I am trying to find what I need to set in update_layout of plotly graph objects to show the background grid.
I want it in light great dashed lines.

I have spent about an hour trying to find what Iโ€™m looking for but to no avail.

i have the following code

fig = go.Figure(
    data = [
        go.Candlestick(
            x = df.index,
            low = df['Low'],
            high = df['High'],
            close = df['Close'],
            open = df['Open'],
            increasing_line_color = 'green',
            decreasing_line_color = 'red'
        )
    ]
    
)

fig.update_layout(xaxis_rangeslider_visible = False, height = 800)
fig.update_layout(
    title = 'Microsoft Share Price 1st Jan 2023 - 1st Jan 2024',
    xaxis_title = 'Date',
    yaxis_title = 'Stock Price - USD ($)',
    plot_bgcolor="rgba(0, 0, 0, 0)",
)
fig.show()

Wwhich created a Shareprice chart quite happily. I have the background colour set to white but I would like to put some x and y grid lines.

I feel that we should be able to finds this stuff easily, either that or Iโ€™m really tired.

I also looked for an โ€˜Anatomy of a chartโ€™ incise I was using the wrong terminology but I cant find one of them either.

@adamschroeder maybe an idea for a future article.

anyone point me at the right place or just suggest what is should stick in my code?

thanks

Tom โ€™ Iโ€™m off to bedโ€™

The easiest way to achieve your wishes is to change the theme rather than setting individual background colors.

fig.update_layout(
    title = 'Microsoft Share Price 1st Jan 2023 - 1st Jan 2024',
    xaxis_title = 'Date',
    yaxis_title = 'Stock Price - USD ($)',
    #plot_bgcolor="rgba(0, 0, 0, 0)",
    template='plotly_white'
)

2 Likes

Thanks. I never use templates hence I never thought of that

Please refer to the https://plotly.com/python/templates/ for a nice example template.

Thanks, thats where I have been playiong for the past 30 mins when I should have been sleeping. Damm, I need to look into templates more. seems like they could save me a heap of fine

Hi @twelsh37 Iโ€™m a bit late to the party, but maybe interesting:

You can switch on/off the gridlines:

fig.update_yaxes(showgrid=True)
fig.update_yaxes(showgrid=False)

To change the style of the grid:

import plotly.graph_objects as go

fig = go.Figure(go.Scatter(x=[1,2], y=[1,2], mode='lines+markers'))
fig.update_xaxes(gridwidth=3, gridcolor='red')
fig.update_yaxes(griddash='dash', gridcolor='black', gridwidth=2)

fig.show()

3 Likes