简体   繁体   English

如何手动为 plotly 散点图中的每个点着色?

[英]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.

相关问题 如何在 plotly (python) 中根据我的数据集中的“颜色”列更改散点图点的颜色? - How can I change the color of my scatter plot points based on a "color" column in my dataset in plotly (python)? 如何控制python散点图中每个点的颜色和不透明度? - How can I control the color and opacity of each point in a python scatter plot? Plotly:如何为散点图中的每个系列设置唯一的颜色? - Plotly: How to set a unique color for each series in a scatter plot? 如何为每个点(散点图)创建一种颜色的散点图? - How to create a scatter plot with one color for each dot (plotly)? 如何在matplotlib中为散点图中的每个点绘制不同深浅的颜色? - How to plot different shades of a color for each point in a scatter plot in matplotlib? 如何使用为每个点单独指定的颜色创建散点图? - How to create a scatter plot with color specified for each point individually? 指定散点图中每个点的颜色(matplotlib) - Specify color of each point in scatter plot (matplotlib) 使用DataFrame.plot设置散点图的颜色 - Set the color for scatter-plot with DataFrame.plot Plotly:如何手动设置 plotly express 散点图中点的颜色? - Plotly: How to manually set the color of points in plotly express scatter plots? 如何创建 3d 散点图以在 plotly 中进行聚类,并将每个点颜色设置为我们选择的颜色? - How to create 3d scatter plots for clustering in plotly with having each point color set to color of our choice?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM