[英]How can I manually color each point in my scatter-plot in plotly?
I have a list of RGB values for each point in my plot, that is not based on a single discrete value nor category, thus built-in methods in plotly express are not working.我的 plot 中的每个点都有一个 RGB 值列表,它既不是基于单个离散值也不是基于类别,因此 plotly 快递中的内置方法不起作用。 I tried using go.Figure(), and adding a new trace for each point, however, that is extremely slow.
我尝试使用 go.Figure(),并为每个点添加一个新的跟踪,但是,这非常慢。 Is there another way of doing this?
还有另一种方法吗? It seems extremely simple, I'm surprised there's no way to pass color values array to the plotting function.
看起来非常简单,我很惊讶没有办法将颜色值数组传递给绘图 function。
marker_color
can be an array. marker_color
可以是一个数组。 See below:见下文:
import math
import plotly.graph_objects as go
import numpy as np
S = 500
a = np.random.randint(0, 255, [S, 3]).astype(str)
a = [f'rgb({",".join(c)})' for c in a]
go.Figure(
go.Scatter(
x=np.linspace(0, S/10, S),
y=np.sin(np.linspace(0, math.pi * S/100, S)),
mode="markers",
marker_color=a,
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.