Chandan Malla
Chandan Malla

Reputation: 445

Why is plotly producing a histogram that seems to be incorrect?

import plotly.express as px

px.histogram(purchase_data,x='Log_Final Price',color='Sale')

Plot with plotly express enter image description here

Same Plot with Seaborn

sns.histplot(purchase_data,x='Log_Final Price',hue='Sale')

You can clearly see, for Sale='Yes' and Sale='Np', plotly is giving completely opposite plot.

enter image description here

Upvotes: 1

Views: 568

Answers (1)

vestland
vestland

Reputation: 61154

The plotly histogram isn't incorrect, it's just stacked. And it will resemble your seaborn histogram more closely if you include:

fig.update_layout(barmode = 'overlay')
fig.update_traces(opacity=0.50)

Plot

enter image description here

Code

import plotly.express as px
df = px.data.tips()
fig = px.histogram(df, x='total_bill', color = 'sex')
fig.update_layout(barmode = 'overlay')
fig.update_traces(opacity=0.50)
fig.show()

Upvotes: 3

Related Questions