将箱形图放在散点图下方 [Plotly]

Putting box plot below scatter plot [Plotly]

我想要将箱线图放置在散点图之上。 无论是首先放置方框轨迹并在顶部添加散点图,还是添加“layer='below'”属性都不会导致所需的结果。盒子总是留在后面。 有什么建议吗?

import plotly.graph_objects as go
import numpy as np

np.random.seed(10)
rand = np.random.uniform(-100, 100, 100)

fig = go.Figure()
fig.add_trace(go.Box(
    x=rand,
    name='Markers',
    line_color='rgba(128, 128, 128, .0)',
    fillcolor='darkgrey'
))
fig.add_trace(go.Scatter(
    x=rand,
    y=['Markers']*len(rand),
    name='Markers',
    mode="markers",
    marker_color='orange',
    marker_size=8,
    # layer='below' # does not work
))
fig.show()

按照建议here,您必须将箱线图附加到另一个轴:

fig = go.Figure()
fig.add_trace(go.Box(
    x=rand,
    name='Markers',
    line_color='rgba(128, 128, 128, .0)',
    fillcolor='darkgrey',
    yaxis='y2'
))
fig.add_trace(go.Scatter(
    x=rand,
    y=['Markers']*len(rand),
    name='Markers',
    mode="markers",
    marker_color='orange',
    marker_size=8
#     layer='below' # does not work
))
fig.update_layout(yaxis2=dict(
        matches='y',
        layer="above traces",
        overlaying="y",       
    ),)

fig.show()