gpt4 book ai didi

python - 将颜色图添加到图表中

转载 作者:太空宇宙 更新时间:2023-11-03 21:23:34 25 4
gpt4 key购买 nike

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,它太酷了。无论如何,我希望在图的侧面添加颜色图,无论我选择什么颜色方案,对我来说可能不可能找到全局颜色图,因为我的颜色渐变起点和终点不同。但是我怎样才能至少在侧面添加一个颜色图来显示最高颜色和最低颜色。有简单的方法吗?

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

最佳答案

{
'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
}

}

我添加了这样的 hack 之一,以暂时解决我的问题。其他人可以建议我更好的方法。我添加了一条不透明度为零的额外迹线,并为其添加了自定义颜色条。它使我能够添加一个不会与其他数据混淆的颜色条。我也可以在任何跟踪中添加此颜色条。

关于python - 将颜色图添加到图表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54029544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com