Text position inside for label and outside for value Pie Chart

Hey Guys,

Is there anyway to get a Pie Chart to have text on the slices and also on the outside? I was reading the documentation for textposition ( enumerated or array of enumerateds : ā€œinsideā€ | ā€œoutsideā€ | ā€œautoā€ | ā€œnoneā€ )

but was not sure how to implement that if possible.

Essentially I would like to plot the label inside and the percent outside

textinfo=ā€˜label+percentā€™,textposition = ā€˜inside for labe, outside for percentā€™

Thanks!

1 Like

I have the same proplem, did you found the answer?

Unfortunately not my friend, if you happen to find a solution please let me know!

I compromised and changed the presentation of the data as it was too cluttered if the value was not able to be presented outside.

Hi @tehnexus and @Luidgi,

I donā€™t think itā€™s possible to place the label inside the wedge and the percent outside, at least not on a single pie trace.

But, hereā€™s a work around that might work for you. If you create a figure with two identical Pie traces they will exactly overlap each other. So if you display the percentage on the outside of the first trace (the one behind) and the label on the inside of the second trace (the one in front) youā€™ll get the appearance that I think you want.

For example:

from plotly.offline import iplot, init_notebook_mode
import plotly.graph_objs as go
init_notebook_mode()

labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']
values = [4500,2500,1053,500]

common_props = dict(labels=labels,
                    values=values,)

trace1 = go.Pie(
    **common_props,
    textinfo='percent',
    textposition='outside')

trace2 = go.Pie(
    **common_props,
    textinfo='label',
    textposition='inside')

iplot([trace1, trace2], filename='basic_pie_chart')

Hope that helps!

4 Likes

Wow, cool lifehack!

Thanks a lot :grin:

Hi, Iā€™m having the same problem.
Is there any way to achieve it with R?
Thanks!