I wanted to plot a scatter plot using plotly in python with specific marker colors. But when I was successful in doing that the legend did not correspond. All the labels are now of same color(blue) in legend. I want legend to represent the risks from my data with same colors as mentioned in code. Like this:
blue marker=moderately low
green marker=moderate
orange marker=moderately high
import plotly.express as px
import plotly.graph_objects as go
colorsIdx = {'Moderately Low': 'blue', 'Moderate': 'green', 'Moderately High': 'orange'}
cols = data['Risk'].map(colorsIdx)
fig = px.scatter(data, x="1_Yr_Return", y="Expense_Ratio", color='Risk')
fig.update_traces(marker=dict(size=12, color=cols), selector=dict(mode='markers'))
fig.show()
color_discrete_map = colorsIdx
inside px.scatter() – vb_rises