I have a dataframe with positive and negative values in one column. I am using plotly barplot, and I’d like customize legend labels based on the value.
Here’s a mock pandas DataFrame:
df = pd.DataFrame({'Date': [07-2020, 08-2020, 09-2020, 10-2020],
'Value': [3, -2, 4, -1] })
df["Color"] = np.where(df["Value"]<0, 'rgb(0,0,255)', 'rgb(255,0,0)')
df["Name"] = np.where(df["Value"]<0, 'Low', 'High')
fig = go.Figure(
data=[
go.Bar(
x=df["Date"],
y=df["Value"],
color=df['Name'],
marker_color=df['Color']
),
],
layout=go.Layout(
xaxis=dict(
tickangle=60,
tickfont=dict(family="Rockwell", color="crimson", size=14)
),
yaxis=dict(
title="Net Change",
showticklabels=True
),
barmode="stack",
)
)
How do I add legend labels Low
when value is negative and High
when positive?