颜色字典
假设你有你的color_dict。Plotly采用与标签和值向量长度相同的颜色数组。因此,您必须自己构造这个数组,例如:import numpy as np
crit = np.array([1, 10, 2, 6, 1, 2, 2, 3, 1, 4, 6, 6, 9, 10, 5, 8, 3, 8,
5, 4, 9, 2, 8, 7, 1, 1, 7, 3, 9, 9, 6, 6, 8, 9, 6, 7, 5,
9, 8, 4, 4, 5, 6, 2, 9, 9, 4, 6, 9, 9])
color_dict = {'1':'#e6f2ff', '2':'#99ccff', '3':'#ccccff',
'4':'#cc99ff', '5':'#ff99ff', '6':'#ff6699',
'7':'#ff9966', '8':'#ff6600', '9':'#ff5050',
'10':'#ff0000'}
colors = np.array([''] * len(crit), dtype = object)
for i in np.unique(crit):
colors[np.where(crit == i)] = color_dict[str(i)]
现在要绘制,只需使用"marker" : {'colors': colors}作为颜色。在
这会给你正确的颜色。在