在Matplotlib颜色图中选择起始颜色 [英] Select starting color in matplotlib colormap

查看:176
本文介绍了在Matplotlib颜色图中选择起始颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下图所示.目前,该图的颜色方案使用了颜色图的整个范围(已配对的cm.cm).我想做的,但一直无法弄清的是如何限制matplotlib仅使用颜色图的一个子集.在这种情况下,我试图将起始颜色设置为较深的蓝色阴影.这是我的代码的绘图部分:

I have the figure shown below. Presently the figure's colorscheme uses the entire range of the colormap (mpl.cm.Paired). What I want to do, and have been unable to figure out, is how to limit matplotlib to use only a subset of the colormap. In this case I am trying to get the starting color to be a darker shade of blue. Here's the plotting section of my code:

Figure = plt.figure(figsize=(22,10))
Map    = Basemap(projection='robin', lon_0=0, resolution='l')
x, y   = Map(LONS, LATS)
levels = np.arange(0, 4100, 100)
fcp    = Map.contourf(x, y, data, levels, interpolation="bicubic", cmap=mpl.cm.Paired)

cb = Map.colorbar(fcp, "bottom", size="5%", pad='5%', extendrect=False)
cb.ax.tick_params(labelsize=18)
cb.solids.set_edgecolor("face")
cb.set_label("metres",fontsize=18)
cb.ax.set_aspect(0.047)

Map.drawcoastlines(linewidth=1)
Map.drawmapboundary(linewidth=1)
Map.drawmeridians([-150,-100,-50,0,50,100, 150],labels=[1,1,1,0],fontsize=18)
Map.drawparallels([-60,-30,0,30,60],labels=[1,1,1,1],fontsize=18)

推荐答案

一种方法是为规范化范围的子集(即[0-1])调用函数mpl.cm.Paired(),然后使用它返回以定义新颜色图的颜色列表:

One way to do this would be to call the function mpl.cm.Paired() for a subset of the normalised range (i.e., [0-1]) and then use the list of colors that it returns to define a new colormap:

import matplotlib.colors as mcol

lvTmp = np.linspace(0.1,1.0,len(levels)-1)
cmTmp = mlp.cm.Paired(lvTmp)
newCmap = mcol.ListedColormap(cmTmp)

您需要弄乱该linspace中的0.1值,才能从内置的颜色图中获得所需的起始颜色.

You'll need to fiddle about with the 0.1 value in that linspace to get the start color that you want from the built in colormap.

这篇关于在Matplotlib颜色图中选择起始颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆