How to change the edgecolor of an Histogram in plotly?

Viewed 1554

I'm trying to change from matplotlib to plotly and I have to relearn every basic move.

One of my habit was to change the edge color of every histogram I made to white so it is easier to see the bars.

On matplotlib, I would do it like that :

import matplotlib.pyplot as plt
import numpy as np

vals = np.random.rand(50)
plt.hist(vals, edgecolor='white');

Which gives me :

matplotlib with edgecolor = white

I suppose there is a way to do it with plotly but I searched in the doc and other stackoverflow questions and haven't found it yet.

Closest way (that make me believe it is somehow possible): setting the template of the figure to a template using white edgecolor

import plotly.express as px
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import numpy as np

vals = np.random.rand(50)

fig = px.histogram(x=vals, template="simple_white")
fig.show()

plotly closest attempt

I also tried to examinate the template simple_white and to look for the param that was making the edges to be white but this didn't lead to anything (if you know what this param is, the answer interests me even more !)

1 Answers

There is function called fig.update_traces you can increase marker(edge) width and change color to 'White' like:

fig = px.histogram(x=vals)
fig.update_traces(marker_line_width=1,marker_line_color="white")
fig.show()

Reference: https://plotly.com/python/reference/histogram/

Related