取决于X轴上图形的颜色编码的点

问题描述 投票:0回答:1

我在plotly图。从本质上讲什么,我试图做的是改变每个点的颜色在图表上,如果在y轴上的值是任何一个值,在给定的列表。

例如:

list = ["ACACT", "TATTC", "CGATT"]

如果这是我的图我要做出相应的任何列表中的红色值的所有点。

Plotly Graph

我当前的图形代码是:

trace = go.scatter(
      x = x1,
      y = x2,
      mode = 'markers'
)
data = [trace]
py.iplot(data, filename='basic-scatter')

我知道你可以使用编辑标记

marker = dict()

但是,你能为特定的点,不喜欢它,我想干什么?

python plotly
1个回答
0
投票

您可以通过颜色列表中colormarker,例如

go.Scatter(x=x
           y=y,
           mode='markers',
           marker={'color': colors})

在下方的默认颜色的例子中,用于所有的点,但有几个那些着色不同基于其使用的y轴值作为其键和颜色作为值的dict

enter image description here

import random 
import plotly 
plotly.offline.init_notebook_mode()

# generate some random x and y-values 
n_points = 10 
y = [] 
for i in range(4):
    _y = 'AT' + 'ATGC'[i]
    y.extend([_y + nuc for nuc in 'ATGC']) 
x = [random.random() for _ in range(n_points * len(y))] 
y = y * n_points

# the default color 
default_color = 'rgb(0,0,255)'

# define our special colors 
special_colors = {'ATAT': 'rgb(255, 0, 0)',
                  'ATTA': 'rgb(0, 255, 0)'}

# build a list of custom 
colors colors = []
for i, y_value in enumerate(y):
    colors.append(special_colors.get(y_value, default_color))

fig = plotly.graph_objs.Figure() 
fig.add_scatter(x=x, y=y, mode='markers', marker={'color': colors}) 
plotly.offline.iplot(fig)
© www.soinside.com 2019 - 2024. All rights reserved.