简体   繁体   中英

Plotly: How to show line for x and y axes with white background?

I'm using plotly while hiding the background

paper_bgcolor='rgba(255,255,255,1)',
plot_bgcolor='rgba(255,255,255,1)',

Unfortunatlly, reading the reference guide of the layout, I couldn't add the axis(only the xy lines on the left and the bottom. Full code:

fig = px.box(pd_data, x="Epoch", y="Cosine similarity", color="Type",
            notched=True, # used notched shape
            title="Box plot of Cos similarity",
            hover_data=["Pair"] # add day column to hover data
            )

fig.update_layout(title_text="",
    paper_bgcolor='rgba(255,255,255,1)',\
plot_bgcolor='rgba(255,255,255,1)',\
              title_font_size=30)

Result: 在此处输入图像描述

You haven't shared a sample of your data, so I'll have to use a setup from box-plots/ . In any case, all you should have to do is set showline=True for both axes like so:

fig.update_xaxes(showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showline=True, linewidth=2, linecolor='black')

Plot:

在此处输入图像描述

Code:

import plotly.express as px
df = px.data.tips()
fig = px.box(df, x="time", y="total_bill", points="all")
f = fig.full_figure_for_development(warn=False)

fig.update_layout(title_text="",
        paper_bgcolor='rgba(255,255,255,1)',\
    plot_bgcolor='rgba(255,255,255,1)',\
                  title_font_size=30)

fig.update_xaxes(showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showline=True, linewidth=2, linecolor='black')

fig.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM