plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

Normalized Histogram with Marginal producing the wrong plot

Open murk3000 opened this issue 2 years ago • 2 comments
trafficstars

Using plotly.express (px) to plot a Histogram with barnorm = 'percent' and marginal = 'histogram' produces a plot where the barnorm is ignored and the raw counts are plotted. I think the output should be a histogram with barnorm = 'percent' and a marginal histogram with the regular counts.

px.histogram(pd.DataFrame({'x': np.random.normal(0, 1, 100),
                           'col': np.random.choice(['A', 'B'], 100)}), 
             x='x', color='col', barnorm='percent', marginal='histogram')

murk3000 avatar Nov 16 '23 10:11 murk3000

It's working if you use the following code:

import plotly.express as px
import pandas as pd
import numpy as np

df = pd.DataFrame({
    'x': np.random.normal(0, 1, 100),                           
    'col': np.random.choice(['A', 'B'], 100)
})

fig = px.histogram(df,
    x='x', 
    color='col', 
    barnorm='percent', 
    marginal='rug'
)

fig.show()

archmoj avatar Nov 21 '23 18:11 archmoj

The rug marginal is different than the histogram marginal in this case. My issue is when the same marginal as the plot (histogram in my code example) is used, the barnorm parameter is ignored.

murk3000 avatar Nov 22 '23 13:11 murk3000