簡體   English   中英

根據ScatterPolar的顏色欄更改fillcolor

[英]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

這是圖像的輸出,但是我希望根據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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM