This article introduces “python How to take it out colomap Part of the color range ” Knowledge about , During the operation of the actual case , Many people will encounter such difficulties , Next, let Xiaobian lead you to learn how to deal with these situations ! I hope you will read carefully , Be able to learn !
Usually when we draw a color map , We often use various colormap, however python Some of the colormap Sometimes the color code is not so suitable , We need to cut it for use .
Official website colormap Example links are as follows :
colormap
This article provides a method , Can be extracted colormap Part of the color code , Take out the color code area we are satisfied with . Let's say jet
For example , demonstrate
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()
Before change :
After modification :
“python How to take it out colomap Part of the color range ” That's all for , Thanks for reading . If you want to know more about the industry, you can pay attention to Yisu cloud website , Xiaobian will output more high-quality practical articles for you !