简体   繁体   English

在Matplotlib颜色图中选择起始颜色

[英]Select starting color in matplotlib colormap

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. 我想做的,但一直无法弄清楚的是如何限制matplotlib仅使用颜色图的一个子集。 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)

在此处输入图片说明

One way to do this would be to call the function mpl.cm.Paired() for a subset of the normalised range (ie, [0-1]) and then use the list of colors that it returns to define a new colormap: 一种方法是为规范化范围的子集(即[0-1])调用mpl.cm.Paired()函数,然后使用它返回的颜色列表来定义新的颜色图:

import matplotlib.colors as mcol

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

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. 您需要在该linspace摆弄0.1值,以从内置的颜色图中获取所需的起始颜色。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM