Skip to content

Commit 1c4b1f5

Browse files
Merge branch 'doc-prod'
2 parents 744930c + 91e75a1 commit 1c4b1f5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

doc/python/histograms.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,21 @@ fig.update_layout(
454454
fig.show()
455455
```
456456

457+
### Sort Histogram by Category Order
458+
459+
Histogram bars can also be sorted based on the ordering logic of the categorical values using the [categoryorder](https://plotly.com/python/reference/layout/xaxis/#layout-xaxis-categoryorder) attribute of the x-axis. Sorting of histogram bars using `categoryorder` also works with multiple traces on the same x-axis. In the following examples, the histogram bars are sorted based on the total numerical values.
460+
461+
```python
462+
import plotly.express as px
463+
import pandas as pd
464+
465+
df = px.data.tips()
466+
fig1 = px.histogram(df, x="day").update_xaxes(categoryorder='total ascending')
467+
fig2 = px.histogram(df, x="day", color="smoker").update_xaxes(categoryorder='total descending')
468+
fig1.show()
469+
fig2.show()
470+
```
471+
457472
#### Reference
458473

459474
See [function reference for `px.histogram()`](https://plotly.com/python-api-reference/generated/plotly.express.histogram) or https://plotly.com/python/reference/histogram/ for more information and chart attribute options!

0 commit comments

Comments
 (0)