Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
470 views
in Technique[技术] by (71.8m points)

python - 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: enter image description here

question from:https://stackoverflow.com/questions/65941311/plotly-how-to-show-line-for-x-and-y-axes-with-white-background

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

enter image description here

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()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...