Why I do not see the x axis when I use plotly with streamlit

Hi,
when I use only plotly I got this :

code :

import plotly.graph_objects as go
import plotly.express as px 
import pandas as pd


data = {'x': [1.5, 1.6, -1.2],
        'y': [21, -16, 46],
        'circle-size': [10, 5, 6],
        'circle-color': ["red","blue","green"]
        }

# Create DataFrame
df = pd.DataFrame(data)
fig = px.scatter(
    df,
    x="x", 
    y="y", 
    color="circle-color",
    size='circle-size'
)


fig.update_layout(
    {
        'xaxis': {
            "range": [-100, 100],
            'zerolinewidth': 3, 
            "zerolinecolor": "blue",
            "tick0": -100,
            "dtick": 25,
            'scaleanchor': 'y'
        },
        'yaxis': {
            "range": [-100, 100],
            'zerolinewidth': 3, 
            "zerolinecolor": "green",
            "tick0": -100,
            "dtick": 25
        },
        "width": 500,
        "height": 500
    }
)
fig.show()

but when I use it with streamlit :

import streamlit as st
import plotly.graph_objects as go
import plotly.express as px 
import pandas as pd


data = {'x': [1.5, 1.6, -1.2],
        'y': [21, -16, 46],
        'circle-size': [10, 5, 6],
        'circle-color': ["red","blue","green"]
        }

# Create DataFrame
df = pd.DataFrame(data)
fig = px.scatter(
    df,
    x="x", 
    y="y", 
    color="circle-color",
    size='circle-size'
)


fig.update_layout(
    {
        'xaxis': {
            "range": [-100, 100],
            'zerolinewidth': 3, 
            "zerolinecolor": "green",
            "tick0": -100,
            "dtick": 25,
            "scaleanchor": 'y'
        },
        'yaxis': {
            "range": [-100, 100],
            'zerolinewidth': 3, 
            "zerolinecolor": "red",
            "tick0": -100,
            "dtick": 25
        },
        "width": 500,
        "height": 500
    }
)
event = st.plotly_chart(fig, key="iris", on_select="rerun")

event.selection

I got this :

why the x axis is removed when I use streamlit ?

thanks for your help

To avoid overrides by Streamlit’s default styling when using st.plotly_chart, make sure to set theme=None. This ensures that the chart’s theme won’t be automatically adjusted by Streamlit, allowing the Plotly figure’s theme to stay intact.

event = st.plotly_chart(fig, key="iris", on_select="rerun", theme=None)

1 Like

@Encrypt thank you very much :wink:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.