DECROMAX

Change legend text plotly.express figs

Feb 28th, 2023
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | Science | 0 0
  1. """Rename's legend in ploty express fig's, from stackoverflow post: https://stackoverflow.com/questions/72885525/plotly-cannot-manually-specify-labels-legend-entries-in-multiple-line-chart)"""
  2.  
  3. new_names = {'example_1':'Example 1', 'example_2: 'Example 2'} # change to suit
  4. fig.for_each_trace(lambda t: t.update(name = newnames[t.name])) # change 'fig' to fig name
  5.            
  6.  
Tags: pandas plotly
Advertisement
Add Comment
Please, Sign In to add comment