Python 基于颜色栏更改ScatterPolar的fillcolor
我正在创建一个带有三个数字的散极图,我有第四个数字,我想确定填充颜色。其中第四个数字可以介于0和1之间,并且颜色条显示该范围的颜色比例 我使用的是plotly 3.1.1和python版本3.6.3 我不知道如何让colorbar影响fillcolor的颜色。以下是我到目前为止的情况:Python 基于颜色栏更改ScatterPolar的fillcolor,python,plotly,Python,Plotly,我正在创建一个带有三个数字的散极图,我有第四个数字,我想确定填充颜色。其中第四个数字可以介于0和1之间,并且颜色条显示该范围的颜色比例 我使用的是plotly 3.1.1和python版本3.6.3 我不知道如何让colorbar影响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 =
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
这是图像的输出,但是我希望根据num_4
的值更改红色:
您可以使用
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