日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

教你python?中如何取出colomap部分的顏色范圍_python

作者:oceanography-Rookie ? 更新時間: 2022-04-20 編程語言

python 如何取出colormap中的部分色標

平常我們在繪制填色圖時,經常會使用到各種colormap,但是python提供的一些 colormap色標有時候不那么合適,需要我們裁剪一下進行使用。
官網colormap例子鏈接如下:
colormap

本文提供了一種方法,可以提取colormap色標中的一部分,取出我們滿意的色標區域。下面以jet為例,進行演示

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()

未改變前:

修改后:

原文鏈接:https://blog.csdn.net/weixin_44237337/article/details/122889771

欄目分類
最近更新