How to remove white lines around bars using plotly.express.bar?

Viewed 811

I have a dataset of > 1000 points. When I plot the histogram with px.bar I get something transparent.

px.bar(df, x='classement', y='scores',title = 'classement', hover_name = 'something', width = 1500, height = 900,
                color_continuous_scale='temps', color = 'classement',facet_col_spacing=0, range_y=[0,1])

Do you have any idea to fix it?

I think the problem is that between each vertical bar there is a tiny space

enter image description here

Thank you in advance

2 Answers

You'll find a similar issue described in Plotly: Bar chart opacity changes with longer time range. The same solution described there will not solve your exact problem though since you'd apparently like to keep the different colors. So here's what you'll need to do:

fig.update_traces(marker_line_width = 0,
                  selector=dict(type="bar"))

fig.update_layout(bargap=0,
                  bargroupgap = 0,
                 )
  • it's simple to hide grid lines .update_layout(xaxis_showgrid=False, yaxis_showgrid=False)
  • full working example below
df = pd.DataFrame(np.sort(np.random.uniform(.4, .9,1000)), columns=["scores"]).reset_index().rename(columns={"index":"classement"}).assign(something=99)

px.bar(df, x='classement', y='scores',title = 'classement', hover_name = 'something', width = 1500, height = 900,
                color_continuous_scale='temps', color = 'classement',facet_col_spacing=0, range_y=[0,1]).update_layout(xaxis_showgrid=False, yaxis_showgrid=False)

10k rows

  • need to set marker_line_width
  • full code below
df = (
    pd.DataFrame(np.sort(np.random.uniform(0.4, 0.9, 10000)), columns=["scores"])
    .reset_index()
    .rename(columns={"index": "classement"})
    .assign(something=99)
)

px.bar(
    df,
    x="classement",
    y="scores",
    title="classement",
    hover_name="something",
    height=900,
    width=1500,
    color_continuous_scale="temps",
    color="classement",
    facet_col_spacing=0,
    range_y=[0, 1],
).update_traces(marker_line_width=0).update_layout(xaxis_showgrid=False, yaxis_showgrid=False)
Related