Switch on/off line connectors to labels in pie chart

I have this pie chart:

import pandas as pd
import plotly.express as px
df = pd.DataFrame([["C", "H", "N", "S", "O"],[0.47514, 0.06385, 0.12931, 0.00794, 0.32376]])
df = df.transpose()
df.columns=["element", "value"]

fig = px.pie(df, values="value", names="element")
fig = fig.update_traces(textposition='auto', textinfo='percent+label', showlegend=False)
fig = fig.update_layout(uniformtext_minsize=20, uniformtext_mode="show", )
fig

image

Can I remove the connecting line to the label? Or better, can I add this line to the other labels outside the pie? Thank you!
I tried looking through the documentation but did not find anything.

1 Like

Alternatively you can set textposition = "inside", but might be a bit squeezed for S.

The leader lines appear dynamically depending on the size of your chart, so if your chart is large enough, those lines shouldn’t appear. You can maximise the chart space by setting the margins to 0.

Not sure if that helps.

1 Like

Thank you for the suggestions. Sadly for my graph this won’t work (texposition="inside" is ugly and text oveflows). Would be better to have an option for switching leader lines off, forcing them on for all outside labels, or being able to position outside labels better (S in my case is shifted too much to right). I’ll raise a feature request on github.

hi! Isn’t possible to turn on leader lines just for design purposes? I mean, I do have enough space to display all categorical % etc, but I still want to show the leader lines