Search code examples
pythonplotlyplotly-python

histogram with opaque bars


If I make a histogram using plotly.express, then the colors cover each other:

import plotly.express as px
df = px.data.tips()
fig = px.histogram(df, x="total_bill", y="tip", color="sex", marginal="rug",
                   hover_data=df.columns)
fig.show()

enter image description here

However, if I use ff.create_distplot, then the colors are more transparent:

import plotly.figure_factory as ff
import numpy as np

# Add histogram data
x1 = np.random.randn(200) - 2
x2 = np.random.randn(200)
x3 = np.random.randn(200) + 2
x4 = np.random.randn(200) + 4

# Group data together
hist_data = [x1, x2, x3, x4]

group_labels = ['Group 1', 'Group 2', 'Group 3', 'Group 4']

# Create distplot with custom bin_size
fig = ff.create_distplot(hist_data, group_labels, bin_size=.2)
fig.show()

enter image description here

This shows transparent colors, which is much nicer.

Is there a way to get the colors to appear like that in px.histogram?


Solution

  • Found it, just use barmode='overlay'