python - 在散点图中标记点

标签 python plotly

我在 plotly 中有一个散点图 - 我想要做的是在不同的点上有特定的字符(比如“*”或“#”)。如下图所示的两个点(粉红色标记)。

我该怎么做(可能使用 these )?

enter image description here

最佳答案

这是一个可能合适的例子。标记可以从 this page 中选择.一个开放的标记看起来很有趣,因为它可以包围一个较小的标记。但是您也可以向 x 和 y 添加一个小的偏移量来定位任何标记。

import random
import plotly.graph_objects as go

N = 20

x1 = [random.gauss(2, .5) for _ in range(N)]
y1 = [random.gauss(2, .5) for _ in range(N)]

x2 = [random.gauss(4, .4) for _ in range(N)]
y2 = [random.gauss(2, .2) for _ in range(N)]

x3 = [random.gauss(3, .4) for _ in range(N)]
y3 = [random.gauss(4, .3) for _ in range(N)]

# x,y for rightmost dot
max_xy = [max(zip(x1,y1)), max(zip(x2,y2)), max(zip(x3,y3))]
max_x = [m[0] for m in max_xy]
max_y = [m[1] for m in max_xy]

fig = go.Figure()
fig.add_trace(go.Scatter(
    x = x1+x2+x3,
    y = y1+y2+y3,
    mode='markers',
    marker=dict(
        size=15,
        color=[.3] * N + [.65] * N + [.8] * N,
        colorscale='jet'
    )
))
fig.add_trace(go.Scatter(
    x = max_x,
    y = max_y,
    mode='markers',
    marker=dict(
        size=30,
        line=dict(width=3, color='pink'),
        symbol=[117, 118, 114]
    )
))
fig.update_layout(showlegend=False)
fig.show()

Resulting plot

关于python - 在散点图中标记点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59003414/

相关文章:

python - TextMate - 在运行 Python 脚本时保持编辑器处于焦点

python - grpc python在客户端和服务器上支持多线程

python - 你如何在 python 中的 plotly 框中设置框宽度?

javascript - Plotly.js - 热图动画非常闪烁

python - 来自 Wavefront OBJ 文件的 Plotly Mesh3d 绘图

python - Plotly 安装与 python-plotly 和 pip install plotly (debian) 的区别

python - 从Python列表列表的内部列表中获取第n个元素

python - 删除 matplotlib 图中经过点的线

python:我可以在模块本身中导入模块命名空间吗?

r - ggplotly 与水平 geom_crossbar() 不匹配原始 ggplot