Skip to content

Commit 954dae6

Browse files
authored
text orientation for pie and sunburst: doc (#2050)
* text orientation for pie and sunburst: doc * radial orientation example in sunburst
1 parent caad61b commit 954dae6

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

doc/python/pie-charts.md

+19
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,25 @@ fig.update_traces(hoverinfo='label+percent', textinfo='value', textfont_size=20,
122122
fig.show()
123123
```
124124

125+
#### Controlling text orientation inside pie sectors
126+
127+
The `insidetextorientation` attribute controls the orientation of text inside sectors. With
128+
"auto" the texts may automatically be rotated to fit with the maximum size inside the slice. Using "horizontal" (resp. "radial", "tangential") forces text to be horizontal (resp. radial or tangential)
129+
130+
For a figure `fig` created with plotly express, use `fig.update_traces(insidetextorientation='...')` to change the text orientation.
131+
132+
```python
133+
import plotly.graph_objects as go
134+
135+
labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']
136+
values = [4500, 2500, 1053, 500]
137+
138+
fig = go.Figure(data=[go.Pie(labels=labels, values=values, textinfo='label+percent',
139+
insidetextorientation='radial'
140+
)])
141+
fig.show()
142+
```
143+
125144
### Donut Chart
126145

127146

doc/python/sunburst-charts.md

+31
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,37 @@ fig.update_layout(
170170
fig.show()
171171
```
172172

173+
#### Controlling text orientation inside sunburst sectors
174+
175+
The `insidetextorientation` attribute controls the orientation of text inside sectors. With
176+
"auto" the texts may automatically be rotated to fit with the maximum size inside the slice. Using "horizontal" (resp. "radial", "tangential") forces text to be horizontal (resp. radial or tangential). Note that `plotly` may reduce the font size in order to fit the text with the requested orientation.
177+
178+
For a figure `fig` created with plotly express, use `fig.update_traces(insidetextorientation='...')` to change the text orientation.
179+
180+
```python
181+
import plotly.graph_objects as go
182+
import pandas as pd
183+
184+
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/718417069ead87650b90472464c7565dc8c2cb1c/coffee-flavors.csv')
185+
186+
fig = go.Figure()
187+
188+
fig.add_trace(go.Sunburst(
189+
ids=df.ids,
190+
labels=df.labels,
191+
parents=df.parents,
192+
domain=dict(column=1),
193+
maxdepth=2,
194+
insidetextorientation='radial'
195+
))
196+
197+
fig.update_layout(
198+
margin = dict(t=10, l=10, r=10, b=10)
199+
)
200+
201+
fig.show()
202+
```
203+
173204
### Sunburst chart with a continuous colorscale
174205

175206
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.

0 commit comments

Comments
 (0)