plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
15.98k stars 2.53k forks source link

Normalized Histogram with Marginal producing the wrong plot #4426

Open murk3000 opened 9 months ago

murk3000 commented 9 months ago

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')
archmoj commented 9 months ago

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()
murk3000 commented 9 months ago

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.