Skip to content

Commit d6d6aa3

Browse files
authored
Merge pull request #2242 from SylwiaOliwia2/patch-5
Update histograms.md
2 parents 8c8d3f6 + 3acbd3c commit d6d6aa3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Diff for: doc/python/histograms.md

+17
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ fig = px.histogram(df, x="total_bill", nbins=20)
6969
fig.show()
7070
```
7171

72+
#### Accessing the counts (y-axis) values
73+
74+
JavaScript calculates the y-axis (count) values on the fly in the browser, so it's not accessible in the `fig`. You can manually calculate it using `np.histogram`.
75+
76+
```python
77+
import plotly.express as px
78+
import numpy as np
79+
80+
df = px.data.tips()
81+
# create the bins
82+
counts, bins = np.histogram(df.total_bill, bins=range(0, 60, 5))
83+
bins = 0.5 * (bins[:-1] + bins[1:])
84+
85+
fig = px.bar(x=bins, y=counts, labels={'x':'total_bill', 'y':'count'})
86+
fig.show()
87+
```
88+
7289
#### Type of normalization
7390

7491
The default mode is to represent the count of samples in each bin. With the `histnorm` argument, it is also possible to represent the percentage or fraction of samples in each bin (`histnorm='percent'` or `probability`), or a density histogram (the sum of bars is equal to 100, `density`), or a probability density histogram (sum equal to 1, `probability density`).

0 commit comments

Comments
 (0)