Interactive Histograms and Distributions
Why interactive distributions
Interactive distributions help you:
- zoom into interesting ranges
- inspect outliers
- compare groups with hover tooltips
Histogram
Histogram
import pandas as pd
import plotly.express as px
df = px.data.tips()
fig = px.histogram(
df,
x="total_bill",
nbins=30,
title="Total bill distribution",
)
fig.show()Histogram
import pandas as pd
import plotly.express as px
df = px.data.tips()
fig = px.histogram(
df,
x="total_bill",
nbins=30,
title="Total bill distribution",
)
fig.show()Histogram by category
Histogram by sex
import plotly.express as px
df = px.data.tips()
fig = px.histogram(
df,
x="total_bill",
color="sex",
nbins=25,
barmode="overlay",
opacity=0.6,
title="Total bill distribution by sex",
)
fig.show()Histogram by sex
import plotly.express as px
df = px.data.tips()
fig = px.histogram(
df,
x="total_bill",
color="sex",
nbins=25,
barmode="overlay",
opacity=0.6,
title="Total bill distribution by sex",
)
fig.show()Box plot (interactive)
Interactive box plot
import plotly.express as px
df = px.data.tips()
fig = px.box(df, x="day", y="total_bill", color="sex", title="Total bill by day")
fig.show()Interactive box plot
import plotly.express as px
df = px.data.tips()
fig = px.box(df, x="day", y="total_bill", color="sex", title="Total bill by day")
fig.show()Tip
Start with a histogram, then add:
- category color
- hover fields
- facet columns/rows
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
