plotly.py
plotly.py copied to clipboard
labels not working in legend un bars
I´m trying the next code, but the atributte labels not is working
import plotly.express as px
d = {'col1': [1, 2, 3], 'col2': [3, 4, 5]}
df = pd.DataFrame(data=d)
fig = px.line(df, x=df.index, y=['col1', 'col2'], labels = {'col1':'hi', 'col2': 'hello'})
fig.show()
for this reason i use
import plotly.express as px
d = {'col1': [1, 2, 3], 'col2': [3, 4, 5]}
df = pd.DataFrame(data=d)
fig = px.line(df, x=df.index, y=['col1', 'col2'])
new_legend_names = {'col1':'hi', 'col2': 'hello'}
fig.for_each_trace(
lambda t: t.update(
name=new_legend_names[t.name],
legendgroup=new_legend_names[t.name],
hovertemplate=t.hovertemplate.replace(t.name, new_legend_names[t.name]),
)
)