✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

How can I change legend title in sunburst chart?

This is my chart, and as you can see the legend title, it says “Ratingaddtional_col_for_hover” (which is supposed to be just “Rating”) and I do not have that name of the column in any of my dataframe. I’m assuming Plotly generated for some reason? And now I’m trying to change the title of this, I’m not able to do so.
I tried using fig.update_layout(legend_title_text='Rating') but it did not work…
How can I change the title and why do I get “Ratingadditional_col_for_hover”?

Thank you!


I think you can add something like this in px.sunburst(),

fig = px.sunburst(top_10, 
                  path=['column-names'], ...., 
                  labels={'Ratingadditional_col_for_hover': 'Rating'})

The `'labels={'column_name': 'new_name'}` should be the new legend title.


To change colorbar title, perform this update:

fig.update_layout(coloraxis_colorbar_title='Your title')

As a rule, when you are defining a figure, via plotly express, inspect fig.data and fig.layout (by running
print(fig.data) respectively print(fig.layout)) to see and decide how some data and/or layout attributes should be updated.