You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you want all the text labels to have the same size, you can use 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. In the example below we also force the text to be outside of bars with `textposition`.
183
+
184
+
```python
185
+
import plotly.express as px
186
+
187
+
df = px.data.gapminder().query("continent == 'Europe' and year == 2007 and pop > 2.e6")
If you want all the text labels to have the same size, you can use 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. In the example below we also force the text to be inside with `textposition`, otherwise text labels which do not fit are displayed outside of pie sectors.
Copy file name to clipboardExpand all lines: doc/python/sunburst-charts.md
+65Lines changed: 65 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,6 +62,53 @@ fig =px.sunburst(
62
62
fig.show()
63
63
```
64
64
65
+
### Sunburst of a rectangular DataFrame with plotly.express
66
+
67
+
Hierarchical data are often stored as a rectangular dataframe, with different columns corresponding to different levels of the hierarchy. `px.sunburst` can take a `path` parameter corresponding to a list of columns. Note that `id` and `parent` should not be provided if `path` is given.
If the dataset is not fully rectangular, missing values should be supplied as `None`. Note that the parents of `None` entries must be a leaf, i.e. it cannot have other children than `None` (otherwise a `ValueError` is raised).
If Plotly Express does not provide a good starting point, it is also possible to use the more generic `go.Sunburst` function from `plotly.graph_objects`.
@@ -201,6 +248,24 @@ fig.update_layout(
201
248
fig.show()
202
249
```
203
250
251
+
### Controlling text fontsize with uniformtext
252
+
253
+
If you want all the text labels to have the same size, you can use 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.
The example below visualizes a breakdown of sales (corresponding to sector width) and call success rate (corresponding to sector color) by region, county and salesperson level. For example, when exploring the data you can see that although the East region is behaving poorly, the Tyler county is still above average -- however, its performance is reduced by the poor success rate of salesperson GT.
Copy file name to clipboardExpand all lines: doc/python/text-and-annotations.md
+39-2Lines changed: 39 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,8 @@ jupyter:
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")
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")
Copy file name to clipboardExpand all lines: doc/python/treemaps.md
+64Lines changed: 64 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,6 +51,52 @@ fig = px.treemap(
51
51
fig.show()
52
52
```
53
53
54
+
### Treemap of a rectangular DataFrame with plotly.express
55
+
56
+
Hierarchical data are often stored as a rectangular dataframe, with different columns corresponding to different levels of the hierarchy. `px.treemap` can take a `path` parameter corresponding to a list of columns. Note that `id` and `parent` should not be provided if `path` is given.
If Plotly Express does not provide a good starting point, it is also possible to use the more generic `go.Treemap` function from `plotly.graph_objects`.
@@ -287,5 +333,23 @@ fig.update_layout(
287
333
fig.show()
288
334
```
289
335
336
+
### Controlling text fontsize with uniformtext
337
+
338
+
If you want all the text labels to have the same size, you can use 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.
0 commit comments