堆积散点图

Stacked scatter plot

是否可以让下面的散点图按“性别”堆叠并按天分组,类似于背景中的条形图?

import plotly.express as px
import plotly.graph_objects as go
df = px.data.tips()

# Scatter Plot
fig = px.strip(df, x='day', y='tip', color='sex').update_traces(jitter = 1)

# Female bars
fig.add_bar(name='Female',
            x=['Sun', 'Sat', 'Thur', 'Fri'], y=[5, 6, 7, 8], marker_color='rgba(0,0,255,0.2)'
           )
# Male bars
fig.add_bar(name='Male',
            x=['Sun', 'Sat', 'Thur', 'Fri'], y=[8, 2, 4, 6], marker_color='rgba(255,0,0,0.2)'
           )

# Make bars stacked
fig.update_layout(barmode='stack')

fig.show()

stripmode='overlay' 完成任务。

import plotly.express as px
import plotly.graph_objects as go
df = px.data.tips()

# Scatter Plot
fig = px.strip(df, x='day', y='tip', color='sex', stripmode='overlay').update_traces(jitter = 1)


# Female bars
fig.add_bar(name='Female',
            x=['Sun', 'Sat', 'Thur', 'Fri'], y=[5, 6, 7, 8], marker_color='rgba(0,0,255,0.2)'
           )

# Male bars
fig.add_bar(name='Male',
            x=['Sun', 'Sat', 'Thur', 'Fri'], y=[8, 2, 4, 6], marker_color='rgba(255,0,0,0.2)'
           )

# Make bars stacked
fig.update_layout(barmode='stack')

fig.show()

给予