Text position inside for label and outside for value Pie Chart

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