我正在尝试创建一个自定义颜色栏,但是色阶看起来与我定义的完全不同-
颜色应该从棕色到白色到蓝色,应该有9个类别。在
我的代码附在下面:
plot = np.clip(plot,40,250)
bounds = [0, 40, 60, 80, 100, 125, 150, 200, 250, 300]
rgblist = [(51,25,0), (102,51,0), (153,76,0), (239,159,80), (255, 255, 255),
(153,204,255), (51,153,255), (0,102,204), (2,2,128)]
clist = [[c/255 for c in rgb] for rgb in rgblist]
cmap = colors.ListedColormap(clist)
norm = colors.BoundaryNorm(bounds, cmap.N)
cs = m.contourf(X,Y,plot,bounds, cmap=cmap, norm=norm)
cbar = m.colorbar(cs, ticks=[20,50,70,90,112.5,137.5,175,225,275])
cbar.set_ticklabels(['<40','40-60', '60-80', '80-100', '100-125', '125-150', '150-200', '200-250', '>250'])
plt.show()
我猜您使用的是python2.x
正在执行整数除法,即结果存储为整数,所有分数信息都将丢失。在您的例子中,这将导致除
255/255
之外的所有除法,结果是0
。在要更改此设置,您可以通过添加小数点来除以浮点:
^{pr2}$或者,您可以通过在除法之前导入python3除法行为
相关问题 更多 >
编程相关推荐