根据ScatterPolar的颜色栏更改fillcolor

时间:2018-11-16 20:28:19

标签: python plotly

我正在创建一个ScatterPolar图,其中附加了三个数字,并且我有第四个数字要确定填充色。第四个数字可以介于0和1之间,并且颜色栏显示该范围的色标。

我正在使用plotly 3.1.1和python版本3.6.3。

我不知道如何获得颜色条来影响fillcolor的颜色。这是我到目前为止的内容:

GROUP BY

这是图像的输出,但是我希望红色根据import plotly.graph_objs as go num_1 = 0.3 num_2 = 0.6 num_3 = 0.9 num_4 = 0.5 # Create radar plot data = [go.Scatterpolar( r = [num_1, num_2, num_3], theta = ['number_1', 'number_2', 'number_3'], fill = 'toself', fillcolor = 'red', # I want this to change based on value of num_4 opacity = 0.5, marker = dict( cmin = 0, cmax = 1, colorbar = dict(title='title'), colorscale = 'Viridis' ), mode = 'markers' )] # Create layout layout = go.Layout( polar = dict( radialaxis = dict(visible = True, range = [0, 1]) ), showlegend = False ) # Plot data (using Jupyter notebook) fig = go.FigureWidget(data=data, layout=layout) fig 的值进行更改: enter image description here

1 个答案:

答案 0 :(得分:1)

您可以使用matplotlib的颜色图来获取rgba值,可视化库通常具有相同的标准颜色图。

import plotly.graph_objs as go
from matplotlib import cm

num_1 = 0.3
num_2 = 0.6
num_3 = 0.9
num_4 = 0.5

cmap = cm.get_cmap('Viridis')

# Create radar plot
data = [go.Scatterpolar(
    r = [num_1, num_2, num_3],
    theta = ['number_1', 'number_2', 'number_3'],
    fill = 'toself',
    fillcolor = 'rgba' + str(cmap(num_4))
    opacity = 0.5,
    marker = dict(
        cmin = 0,
        cmax = 1,
        colorbar = dict(title='title'),
        colorscale = 'Viridis'
    ),
    mode = 'markers'
)]

# Create layout
layout = go.Layout(
    polar = dict(
        radialaxis = dict(visible = True, range = [0, 1])
    ),
    showlegend = False
)

# Plot data (using Jupyter notebook)
fig = go.FigureWidget(data=data, layout=layout)
fig
相关问题