plotly / plotly.py

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

Set barmode="overlay" in histograms by default to avoid misunderstandings #4893

Open pierre-eliep-met opened 1 week ago

pierre-eliep-met commented 1 week ago

Reopening of #1865, as asked in the comment.

By default, histograms are not overlayed, which leads to misinterpretation :

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

x0 = np.random.randn(250)
# Add 1 to shift the mean of the Gaussian distribution
x1 = np.random.randn(250) + 1

df = pd.DataFrame(dict(
    series=np.concatenate((["a"] * len(x0), ["b"] * len(x1))), 
    data=np.concatenate((x0, x1))
))

px.histogram(df, x="data", color="series")

Makes think that there is much more points in red distribution : Image

While overlying clearly shows that it is just shifted

px.histogram(df, x="data", color="series", barmode="overlay")

Image

This leads to misunderstanding the data shape.

gvwilson commented 16 hours ago

@archmoj is this a plotly.py issue or should I move it to plotly.js?