diff --git a/doc/python/pie-charts.md b/doc/python/pie-charts.md index d5e8e54449d..ec65c9b4402 100644 --- a/doc/python/pie-charts.md +++ b/doc/python/pie-charts.md @@ -122,6 +122,25 @@ fig.update_traces(hoverinfo='label+percent', textinfo='value', textfont_size=20, fig.show() ``` +#### Controlling text orientation inside pie sectors + +The `insidetextorientation` attribute controls the orientation of text inside sectors. With +"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) + +For a figure `fig` created with plotly express, use `fig.update_traces(insidetextorientation='...')` to change the text orientation. + +```python +import plotly.graph_objects as go + +labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen'] +values = [4500, 2500, 1053, 500] + +fig = go.Figure(data=[go.Pie(labels=labels, values=values, textinfo='label+percent', + insidetextorientation='radial' + )]) +fig.show() +``` + ### Donut Chart diff --git a/doc/python/sunburst-charts.md b/doc/python/sunburst-charts.md index a80d530fc08..c0b01c61895 100644 --- a/doc/python/sunburst-charts.md +++ b/doc/python/sunburst-charts.md @@ -170,6 +170,37 @@ fig.update_layout( fig.show() ``` +#### Controlling text orientation inside sunburst sectors + +The `insidetextorientation` attribute controls the orientation of text inside sectors. With +"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. + +For a figure `fig` created with plotly express, use `fig.update_traces(insidetextorientation='...')` to change the text orientation. + +```python +import plotly.graph_objects as go +import pandas as pd + +df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/718417069ead87650b90472464c7565dc8c2cb1c/coffee-flavors.csv') + +fig = go.Figure() + +fig.add_trace(go.Sunburst( + ids=df.ids, + labels=df.labels, + parents=df.parents, + domain=dict(column=1), + maxdepth=2, + insidetextorientation='radial' +)) + +fig.update_layout( + margin = dict(t=10, l=10, r=10, b=10) +) + +fig.show() +``` + ### Sunburst chart with a continuous colorscale 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.