From 0d9339a6d79dcbeaada74f009bcd41f00ce2ccc2 Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Thu, 9 Jan 2020 14:05:59 -0500 Subject: [PATCH 1/2] text orientation for pie and sunburst: doc --- doc/python/pie-charts.md | 19 +++++++++++++++++++ doc/python/sunburst-charts.md | 31 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) 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..39434b962ef 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=df2.ids, + labels=df2.labels, + parents=df2.parents, + domain=dict(column=1), + maxdepth=2, + insidetextorientation='horizontal' +)) + +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. From 47deecfb537e014dc5710fb5a50fba195884b67b Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Tue, 14 Jan 2020 11:23:32 -0500 Subject: [PATCH 2/2] radial orientation example in sunburst --- doc/python/sunburst-charts.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/python/sunburst-charts.md b/doc/python/sunburst-charts.md index 39434b962ef..c0b01c61895 100644 --- a/doc/python/sunburst-charts.md +++ b/doc/python/sunburst-charts.md @@ -186,12 +186,12 @@ df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/718417069ead fig = go.Figure() fig.add_trace(go.Sunburst( - ids=df2.ids, - labels=df2.labels, - parents=df2.parents, + ids=df.ids, + labels=df.labels, + parents=df.parents, domain=dict(column=1), maxdepth=2, - insidetextorientation='horizontal' + insidetextorientation='radial' )) fig.update_layout(