|
5 | 5 | text_representation:
|
6 | 6 | extension: .md
|
7 | 7 | format_name: markdown
|
8 |
| - format_version: "1.1" |
9 |
| - jupytext_version: 1.2.1 |
| 8 | + format_version: '1.2' |
| 9 | + jupytext_version: 1.3.0 |
10 | 10 | kernelspec:
|
11 | 11 | display_name: Python 3
|
12 | 12 | language: python
|
@@ -90,6 +90,43 @@ fig.add_trace(go.Scatter(
|
90 | 90 | fig.show()
|
91 | 91 | ```
|
92 | 92 |
|
| 93 | +### Controlling text fontsize with uniformtext |
| 94 | + |
| 95 | +For the [pie](/python/pie-charts), [bar](/python/bar-charts), [sunburst](/python/sunburst-charts) and [treemap](/python/treemap-charts) traces, it is possible to force all the text labels to have the same size thanks to the `uniformtext` layout parameter. The `minsize` attribute sets the font size, and the `mode` attribute sets what happens for labels which cannot fit with the desired fontsize: either `hide` them or `show` them with overflow. |
| 96 | + |
| 97 | +```python |
| 98 | +import plotly.express as px |
| 99 | + |
| 100 | +df = px.data.gapminder().query("continent == 'Europe' and year == 2007 and pop > 2.e6") |
| 101 | +fig = px.bar(df, y='pop', x='country', text='pop') |
| 102 | +fig.update_traces(texttemplate='%{text:.2s}', textposition='outside') |
| 103 | +fig.update_layout(uniformtext_minsize=8, uniformtext_mode='hide') |
| 104 | +fig.show() |
| 105 | +``` |
| 106 | + |
| 107 | +```python |
| 108 | +import plotly.express as px |
| 109 | + |
| 110 | +df = px.data.gapminder().query("continent == 'Asia' and year == 2007") |
| 111 | +fig = px.pie(df, values='pop', names='country') |
| 112 | +fig.update_traces(textposition='inside') |
| 113 | +fig.update_layout(uniformtext_minsize=12, uniformtext_mode='hide') |
| 114 | +fig.show() |
| 115 | +``` |
| 116 | + |
| 117 | +### Controlling text fontsize with textfont |
| 118 | + |
| 119 | +The `textfont_size` parameter of the the [pie](/python/pie-charts), [bar](/python/bar-charts), [sunburst](/python/sunburst-charts) and [treemap](/python/treemap-charts) traces can be used to set the **maximum font size** used in the chart. Note that the `textfont` parameter sets the `insidetextfont` and `outsidetextfont` parameter, which can also be set independently. |
| 120 | + |
| 121 | +```python |
| 122 | +import plotly.express as px |
| 123 | + |
| 124 | +df = px.data.gapminder().query("continent == 'Asia' and year == 2007") |
| 125 | +fig = px.pie(df, values='pop', names='country') |
| 126 | +fig.update_traces(textposition='inside', textfont_size=14) |
| 127 | +fig.show() |
| 128 | +``` |
| 129 | + |
93 | 130 | ### Adding Hover Text to Data in Line and Scatter Plots
|
94 | 131 |
|
95 | 132 | ```python
|
|
0 commit comments