如何绘制覆盖其他标记的标记?

问题描述 投票:0回答:1

我使用 Plotly 绘制散点图:

go.Scatter(x=df["x"], y=df["y"], mode='markers')

Present

我想添加一个红色圆圈来覆盖绘制的标记,如下所示:

What I want

如何添加红色圆圈?

python-3.x plotly scatter-plot
1个回答
0
投票

您可以查看 Plotly 教程中的 Shapes 部分。它有一个例子可以完成你刚才问的。

import plotly.graph_objects as go

import numpy as np
np.random.seed(1)

# Generate data
x0 = np.random.normal(2, 0.45, 300)
y0 = np.random.normal(2, 0.45, 300)

# Create figure
fig = go.Figure()

# Add scatter traces
fig.add_trace(go.Scatter(x=x0, y=y0, mode="markers"))

# Add shapes
fig.add_shape(type="circle",
    xref="x", yref="y",
    x0=min(x0), y0=min(y0),
    x1=max(x0), y1=max(y0),
    opacity=0.2,
    fillcolor="red",
    line_color="red",
)

# Hide legend
fig.update_layout(showlegend=False)

fig.show()
© www.soinside.com 2019 - 2024. All rights reserved.