简体   繁体   English

将盒子 plot 放在散点下方 plot [Plotly]

[英]Putting box plot below scatter plot [Plotly]

I want a box plot to be placed on top of a scatter plot. Neither putting the box trace at first and adding the scatter plot on top nor adding an "layer='below'" attribute leads to the desired result.我想要一个盒子 plot 放在散点图 plot 的顶部。首先放置盒子轨迹并在顶部添加散点图 plot 或添加“layer='below'”属性都不会导致所需的结果。 The box always stays in the back.盒子总是留在后面。 Any suggestions?有什么建议么?

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()

在此处输入图像描述

As suggested here , you have to attach the box plot to another axis:正如此处所建议的,您必须将框 plot 附加到另一个轴:

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()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM