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]),
)
)
Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for a while, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson