简体   繁体   English

如何在 Plotly 3D 散点图中设置点标记的样式/格式?

[英]How to style/format point markers in Plotly 3D scatterplot?

I am unsure how to customize scatterplot marker styles in Plotly scatterplots.我不确定如何在 Plotly 散点图中自定义散点图标记 styles。

Specifically, I have a column predictions that is 0 or 1 (1 represents an unexpected value) and even though I used the symbol parameter in px.scatter_3d to indicate the unexpected value through varying point shape (diamond for 1 and circle for 0), the difference is very subtle and I want it to be more dramatic.具体来说,我有一列predictions为 0 或 1(1 表示意外值),即使我使用 px.scatter_3d 中的symbol参数通过不同的点形状(菱形表示 1,圆形表示 0)来指示意外值,差异非常微妙,我希望它更具戏剧性。 I was envisioning something like below (doesn't need to be exactly this), but something along the lines of the diamond shaped points have a different outline colors or an additional shape/bubble around it.我正在设想类似下面的东西(不需要完全是这样),但是沿着菱形点的线条有不同的轮廓 colors 或它周围的额外形状/气泡。 How would I do this?我该怎么做?

Additionally, I have a set column which can take on one of two values, set A or set B. I used the color parameter inside px.scatter_3d and made that equal to set so the points are colored according to which set it came from.此外,我有一个set列,它可以采用两个值之一,即 set A 或 set B。我在px.scatter_3d中使用了 color 参数并将其设置为等于set ,因此这些点根据它来自哪个 set 进行着色。 While it is doing what I asked, I don't want the colors to be blue and red, but any two colors I specify.虽然它按照我的要求执行,但我不希望 colors 是蓝色和红色,而是我指定的任何两个 colors。 How would I be able to this (let's say I want the colors to be blue and orange instead)?我怎么能做到这一点(假设我希望 colors 改为蓝色和橙色)? Thank you so much!太感谢了!

在此处输入图像描述

Here is the code I used:这是我使用的代码:

fig = px.scatter_3d(X_combined, x='x', y='y', z='z',
                    color='set', symbol='predictions', opacity=0.7)

fig.update_traces(marker=dict(size=12,
                         line=dict(width=5,
                         color='Black')),
              selector=dict(mode='markers'))

You can use multiple go.Scatter3d() statements and gather them in a list to format each and every segment or extreme values more or less exactly as you'd like.您可以使用多个go.Scatter3d()语句并将它们收集在一个列表中,以或多或少地根据您的需要格式化每个段或极值。 This can be a bit more demanding than using px.scatter_3d() , but it will give you more control.这可能比使用px.scatter_3d()要求更高,但它会给你更多的控制权。 The following plot is produced by the snippet below:以下 plot 由以下代码段生成:

Plot: Plot:

在此处输入图像描述

Code:代码:

import plotly.graph_objects as go
import numpy as np
import pandas as pd

# sample data
t = np.linspace(0, 10, 50)
x, y, z = np.cos(t), np.sin(t), t

# plotly data
data=[go.Scatter3d(x=[x[2]], y=[y[2]], z=[z[2]],mode='markers', marker=dict(size=20), opacity=0.8),
      go.Scatter3d(x=[x[26]], y=[y[26]], z=[z[26]],mode='markers', marker=dict(size=30), opacity=0.3),
      go.Scatter3d(x=x, y=y, z=z,mode='markers')]

fig = go.Figure(data)
fig.show()

How you identify the different segmens, whether it be max or min values will be entirely up to you.如何识别不同的段,无论是最大值还是最小值,完全取决于您。 Anyway, I hope this approach will be useful!无论如何,我希望这种方法会有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM