Python 如何为每个点(plotly)创建一种颜色的散点图?

Python 如何为每个点(plotly)创建一种颜色的散点图?,python,plot,plotly,Python,Plot,Plotly,我需要使用plot.ly的在线版本创建一个绘图,其中每个点对应一种颜色。我看到可以通过在数据部分中的x和y列旁边添加一列带有颜色代码的列来实现这一点,但我不知道如何指示plot.ly这是颜色列。 举个例子: 点击“fork and edit”按钮,然后尝试用提供的数据重现结果,我不能!“跟踪”中可用的选项比我创建数据集时可以访问的选项要完整得多 以下是截图: 你知道怎么做吗?非常感谢您提前为您要自定义的每个“属性”和每个点列出一个列表。我需要不同的颜色和文字为每个点 colors = [] t

我需要使用plot.ly的在线版本创建一个绘图,其中每个点对应一种颜色。我看到可以通过在数据部分中的x和y列旁边添加一列带有颜色代码的列来实现这一点,但我不知道如何指示plot.ly这是颜色列。 举个例子:

点击“fork and edit”按钮,然后尝试用提供的数据重现结果,我不能!“跟踪”中可用的选项比我创建数据集时可以访问的选项要完整得多

以下是截图:


你知道怎么做吗?非常感谢您提前为您要自定义的每个“属性”和每个点列出一个列表。我需要不同的颜色和文字为每个点

colors = []
texts = []
x_values = []
y_values = []
为了清楚起见,这些是列表中列出的值:

init_anchor_text = "Initial Anchor No.%d"
anchor_text_real = "Localized Anchor No.%d - real values"
anchor_text = "Localized Anchor No.%d"
unknown_text = "Unknown Node No.%d"
init_anchor_color = 'rgba(50, 96, 171,.9)'
anchor_color = 'rgba(50, 171, 96,.9)'
anchor_color_real = 'rgba(171, 171, 50,.9)'
unknown_color = 'rgba(171, 50, 96,.9)'
x_values.append(node.calc_x)
y_values.append(node.calc_y)
colors.append(init_anchor_color)
texts.append((init_anchor_text % node.number))
在我的for循环中执行了几个if之后,我就是这样通过简单地使用append-to-the-list来输入值的:

init_anchor_text = "Initial Anchor No.%d"
anchor_text_real = "Localized Anchor No.%d - real values"
anchor_text = "Localized Anchor No.%d"
unknown_text = "Unknown Node No.%d"
init_anchor_color = 'rgba(50, 96, 171,.9)'
anchor_color = 'rgba(50, 171, 96,.9)'
anchor_color_real = 'rgba(171, 171, 50,.9)'
unknown_color = 'rgba(171, 50, 96,.9)'
x_values.append(node.calc_x)
y_values.append(node.calc_y)
colors.append(init_anchor_color)
texts.append((init_anchor_text % node.number))
这是散布和绘图:

trace = go.Scatter(
    x=x_values,
    y=y_values,
    mode='markers',
    text=text,
    marker=dict(
        size=10,
        color=colors,
        line=dict(
            width=2,
        )
    )
)

fig = {
    'data': [trace],
    'layout': layout,
}
plotly.offline.plot(fig, filename='TriangulationExercise.html')

看起来是罗伊格散射。您可以在Plotly web app中为点着色,但选项有限。对于Python,您可能会喜欢我们的颜色比例支持。这是一个有步行通道的房间。