[英]Change fillcolor based on colorbar for ScatterPolar
我正在创建一个ScatterPolar图,其中附加了三个数字,并且我有第四个数字要确定fillcolor。 第四个数字可以介于0和1之间,并且色条显示该范围的色标。
我正在使用plotly 3.1.1和python版本3.6.3。
我无法弄清楚如何获得颜色条来影响fillcolor的颜色。 这是我到目前为止的内容:
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
您可以使用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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.