python 如何取出colormap中的部分色标
平常我们在绘制填色图时,经常会使用到各种colormap,但是python提供的一些 colormap色标有时候不那么合适,需要我们裁剪一下进行使用。
官网colormap例子链接如下:
colormap
本文提供了一种方法,可以提取colormap色标中的一部分,取出我们满意的色标区域。下面以jet
为例,进行演示
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable import numpy as np from matplotlib.colors import ListedColormap, LinearSegmentedColormap ax = plt.subplot() cmap = plt.get_cmap( 'jet' ) newcolors = cmap(np.linspace( 0 , 1 , 256 )) newcmap = ListedColormap(newcolors[ 57 : 245 ]) im = ax.imshow(np.arange( 100 ).reshape(( 10 , 10 )),cmap = newcmap) # create an axes on the right side of ax. The width of cax will be 5% # of ax and the padding between cax and ax will be fixed at 0.05 inch. divider = make_axes_locatable(ax) cax = divider.append_axes( "right" , size = "5%" , pad = 0.05 ) plt.colorbar(im, cax = cax) plt.show() |
未改变前:
修改后:
到此这篇关于python 中如何取出colomap部分的颜色范围的文章就介绍到这了,更多相关python 内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/weixin_44237337/article/details/122889771