Skip to content

Commit 7c63767

Browse files
committed
Add histogram texttemplate example
1 parent 9e281a0 commit 7c63767

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

doc/python/histograms.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.2'
9-
jupytext_version: 1.4.2
8+
format_version: '1.3'
9+
jupytext_version: 1.13.4
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.7
23+
version: 3.7.11
2424
plotly:
2525
description: How to make Histograms in Python with Plotly.
2626
display_as: statistical
@@ -340,6 +340,24 @@ fig.update_layout(
340340
fig.show()
341341
```
342342

343+
### Histogram Bar Text
344+
345+
346+
You can add text to histogram bars using the `texttemplate` argument. In this example we add the x-axis values as text following the format `%{variable}`. We also adjust the size of the text using `textfont_size`.
347+
348+
349+
350+
```python
351+
import plotly.graph_objects as go
352+
353+
numbers = ["5", "10", "3", "10", "5", "8", "5", "5"]
354+
355+
fig = go.Figure()
356+
fig.add_trace(go.Histogram(x=numbers, name="count", texttemplate="%{x}", textfont_size=20))
357+
358+
fig.show()
359+
```
360+
343361
### Cumulative Histogram
344362

345363
```python

0 commit comments

Comments
 (0)