I am looking to change the color of the points in the box plot based on a column value from the data frame (committed).
users = ['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c']
cost = [87.25, 84.69, 82.32, 87.25, 84.59, 82.32, 89.45, 86.37, 83.83]
committed = ['f', 'f', 't', 't', 'f', 'f', 'f', 't', 'f']
df = pd.DataFrame({'user': users, 'cost': cost, 'committed': committed})
To get the below plot, I entered this:
fig = go.Figure(
data=[go.Box(
x=df['user'],
y=df['cost'],
boxpoints='all',
jitter=.3,
pointpos=-1.8,
)]
)
fig.show()
I have found this post for r and was hoping in the past 5 years, something has changed to make it possible: Coloring jitters in a plotly box plot by group variable
I have tried this, but it does not appear that the marker or marker_color accepts what I attempted and I am unsure how to set the values otherwise.
def set_color(point):
if point == 't':
return "red"
elif point == 'f':
return "blue"
fig = go.Figure(
data=[go.Box(
x=df['user'],
y=df['cost'],
boxpoints='all',
jitter=.3,
pointpos=-1.8,
marker=dict(color=list(map(set_color, df['committed'])))
)]
)
fig.show()
Error:
Invalid value of type 'builtins.list' received for the 'color' property of box.marker