Plotly express legend

How i can remove the “country=” not to be part of every legend?

import as px

fig = px.scatter(df, x="rank", y="value", color='country', animation_frame="year", 
                  size='value', hover_data=['name'], width=1100, height=600)
1 Like

Hi @rpeter,
since the legend item of a trace is given by its name attribute, you can iterate through the traces to modify the names as below (as a rule of thumb, it helps to do print(fig) to see the structure of the figure and understand how to modify it).

import as px
df ="year == 2007").query("continent == 'Europe'")
fig = px.scatter(df, x='gdpPercap', y='lifeExp', color='country')
for trace in ='=')[1]

That said, legend titles is something we want to add in and when it’s implemented the name of the column will be the title, so by default you will not have the column name repeated in legend items. Please stay tuned for future developments :-).

1 Like

Now I’m scratching my head… and thinking… "why I didn’t think about that before posting… :smiley: "

Thank you, i appreciate your time.