向ch添加plotly colormap

2024-09-29 19:33:35 发布

您现在位置:Python中文网/ 问答频道 /正文

import plotly
import plotly.graph_objs as go
import matplotlib.pyplot as plt
import numpy as np

plotly.offline.init_notebook_mode(connected=True)
colorscale='Earth'
#print("     :  Min  :   Q1   : Median :   Q3   :    Max  :  Mean  : Good Mean : Good STD : Outliers :")
data = [
    {
        'x': ['Min','Min','Min','Min','Min'],
        'y': ['config1','config2','config3','config4','config5'],
        'mode': 'markers',
        'marker': {
            'color': [0.89,0.892,0.886,0.901,0.869],
            'size': [30, 30, 30, 30, 30],
            'showscale': False,
            'colorscale':colorscale,
            'reversescale':True,
            'cmin':0.865,
            'cmax':0.901,
        }
    },
    {
        'x': ['Q1','Q1','Q1','Q1','Q1'],
        'y': ['config1','config2','config3','config4','config5'],
        'mode': 'markers',
        'marker': {
            'color': [0.912,0.908,0.892,0.915,0.889],
            'size': [30, 30, 30, 30, 30],
            'showscale': False, 
            'colorscale':colorscale,
            'reversescale':True,
            'cmin':0.885,
            'cmax':0.915,
        }
    },
    {
        'x': ['Median','Median','Median','Median','Median'],
        'y': ['config1','config2','config3','config4','config5'],
        'mode': 'markers',
        'marker': {
            'color': [0.919,0.912,0.914,0.917,0.9],
            'size': [30, 30, 30, 30, 30],
            'showscale': False,
            'colorscale':colorscale,
            'reversescale':True,
            'cmin':0.89,
            'cmax':0.919,
        }
    },
    {
        'x': ['Q3','Q3','Q3','Q3','Q3'],
        'y': ['config1','config2','config3','config4','config5'],
        'mode': 'markers',
        'marker': {
            'color': [0.929,0.919,0.925,0.922,0.909],
            'size': [30, 30, 30, 30, 30],
            'showscale': False,
            'colorscale':colorscale,
            'reversescale':True,
            'cmin':0.90,
            'cmax':0.929,
        }
    },
    {
        'x': ['Max','Max','Max','Max','Max'],
        'y': ['config1','config2','config3','config4','config5'],
        'mode': 'markers',
        'marker': {
            'color': [0.95,0.932,0.933,0.935,0.935],
            'size': [30, 30, 30, 30, 30],
            'showscale': False, 
            'colorscale':colorscale,
            'reversescale':True,
            'cmin':0.93,
            'cmax':0.95,
        }
    },
    {
        'x': ['Mean','Mean','Mean','Mean','Mean'],
        'y': ['config1','config2','config3','config4','config5'],
        'mode': 'markers',
        'marker': {
            'color': [0.921,0.912,0.91,0.918,0.9],
            'size': [30, 30, 30, 30, 30],
            'showscale': False, 
            'colorscale':colorscale,
            'reversescale':True,
            'cmin':0.898,
            'cmax':0.921,
        }
    }
]
layout = go.Layout(title='Parameters of evaluation', xaxis=dict(range=[-0.5, 10]), yaxis=dict(range=[-0.5, 5.5]))
fig = go.Figure(data=data, layout=layout)                           

#plotly.offline.iplot(data, filename='scatter-colorscale')
plotly.offline.iplot(fig)

大家好,我正在做一个可视化的工作,今天才开始用plotly,太酷了。不管怎样,我希望在图表的侧面添加colormap,不管我选择什么颜色方案,对我来说,可能找不到全局colormap,因为我的颜色渐变起点和终点是不同的。但我怎么能至少添加一个彩色地图在一边,显示哪一个是最高的颜色和什么是最低的颜色。有简单的方法吗?你知道吗

I want to add colormap like this, at right hand side

The output image i have right now looks like this, apart from the trace and title etc which I have to remove later, somehow.I wanted to do this, in a proper way


Tags: truemodeplotlyminmeanmaxmedianq3
1条回答
网友
1楼 · 发布于 2024-09-29 19:33:35
{
        'x': ['Mean','Mean','Mean','Mean','Mean'],
        'y': ['config1','config2','config3','config4','config5'],
        'mode': 'markers,text',
        'marker': {
            'colorbar':dict(nticks=3,tickmode='array',tickvals=[2,4.5,7],showticklabels=True,ticktext=['lowest','middle','highest']),
            'size': [30, 30, 30, 30, 30],
            'showscale': True, 
            'colorscale':colorscale,
            'reversescale':True,
            'opacity':0
        }

    }

我添加了一个这样的黑客,来解决我的问题。其他人可以给我建议更好的方法。我添加了一个额外的跟踪不透明度为零,并添加了一个自定义的色条。它使我能够添加一个不与其他数据混乱的色条。我也可以把这个色条加到任何一个痕迹里。你知道吗

相关问题 更多 >

    热门问题