TestGuest
TestGuest

Reputation: 603

Marker over plotly dots in a scatterplot

I have a scatterplot in plotly - what I want to do is to have specific characters (say a "*" or a "#") over different dots. Something like illustrated for two dots in the figure below (markers in pink).

How can I do that (possibly using these)?

enter image description here

Upvotes: 3

Views: 870

Answers (1)

JohanC
JohanC

Reputation: 80279

Here is an example that might be suitable. The markers can be chosen from this page. An open marker looks interesting, as it can enclose a smaller marker. But you could also add a small offset to the x and y to position any marker.

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

Upvotes: 2

Related Questions