How to set the x-axis and y-axis as the frame line in plotly?

Dear All,

The current python code with plotly in the google colab results in Picture A.

What I want is Picture B (the frame as the x-axis and y-axis are black lines).

Here is the current code:

# x and y given as array_like objects
import as px

df = df_final
df["Optimality"] = df["Optimality"].astype(str)
fig = px.scatter(df, x="P2", y="C2", color = "Optimality", width=800, height=800, color_discrete_sequence=["white", "green"], category_orders={"Optimality": ["0", "1"]})

        'text': r'$\textit{Backward(0) Sequence}$',  # Use LaTeX formatting for title
        'y':0.95,  # Adjust the y position of the title
        'x':0.5,  # Center the title horizontally
        'xanchor': 'center',
        'yanchor': 'top',
        'font': dict(family='Times New Roman',size=30, color="Black")  # Set the font size of the title
    xaxis=dict(title=dict(text="Optimality", font=dict(family="Times New Roman", size=30))),  # Set the font size of the x-axis label
    xaxis_title=r'$p_2$',  # Use LaTeX formatting for x-axis title
    font=dict(family="Times New Roman", size=20, color="Black"),
    legend=dict(itemsizing="constant", font=dict(size=20),title=dict(text='Optimality', font=dict(family='Times New Roman', size=18))))

What should I do? Thank you.

I think update xaxes and yaxes with mirror=True may help. Something as below:

import as px
df =
fig =, x="day", y="total_bill", color="smoker", barmode="group", facet_col="sex",
             category_orders={"day": ["Thur", "Fri", "Sat", "Sun"],
                              "smoker": ["Yes", "No"],
                              "sex": ["Male", "Female"]})
fig.update_layout(plot_bgcolor = "white")
fig.update_xaxes(showline=True, linewidth=1, linecolor='black', mirror=True)
fig.update_yaxes(showline=True, linewidth=1, linecolor='black', mirror=True)

1 Like