0

I just started using plotly and I'm trying to format markers on my plotly pie chart based on the example here. When I do so, it only changes the marker formatting for one of the markers, not for all of them. This appears to be the case in the example on the plotly website as well. If you follow the link and look at the Styled Pie Chart, only Hydrogen has the white font, while all others have black font.

How can I make all of the markers have the same text formatting?

My code:

trace = go.Pie(labels=labels, values=values, hoverinfo='label+value', textinfo='percent', 
           textfont=dict(size=20, color='#ffffff'),
           marker=dict(line=dict(color='#ffffff', width=2)))

Any help on how I can apply it to all markers would be greatly appreciated.

1 Answer 1

2

If you want to change the format of hover info/hover label of a Pie chart in Plotly you would need to set the hoverlabel parameters.

import plotly
plotly.offline.init_notebook_mode()
labels = ['Oxygen', 'Hydrogen', 'Carbon_Dioxide', 'Nitrogen']
values = [4500, 2500, 1053, 500]

trace = plotly.graph_objs.Pie(labels=labels, 
                              values=values,
                              textfont=dict(size=20),
                              hoverlabel=dict(bgcolor='black', 
                                              font=dict(color='white')
                                             )
                             )
plotly.offline.iplot([trace])

The snippet above would give hover labels with black background and a white font.

enter image description here

In your code textfont and marker specify the format of the labels inside the pie chart, not the hover labels. Plotly picks the colors for you if you don't specify them, it's just an accident that they match your color setting sometimes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.