教你python 中如何取出colomap部分的顏色范圍
python 如何取出colormap中的部分色標
平常我們在繪制填色圖時,經(jīng)常會使用到各種colormap,但是python提供的一些 colormap色標有時候不那么合適,需要我們裁剪一下進行使用。
官網(wǎng)colormap例子鏈接如下:
colormap

本文提供了一種方法,可以提取colormap色標中的一部分,取出我們滿意的色標區(qū)域。下面以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()未改變前:

修改后:

到此這篇關(guān)于python 中如何取出colomap部分的顏色范圍的文章就介紹到這了,更多相關(guān)python 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python Datetime模塊和Calendar模塊用法實例分析
這篇文章主要介紹了Python Datetime模塊和Calendar模塊用法,結(jié)合實例形式分析了Python日期時間及日歷相關(guān)的Datetime模塊和Calendar模塊原理、用法及操作注意事項,需要的朋友可以參考下2019-04-04
使用pandas中的DataFrame數(shù)據(jù)繪制柱狀圖的方法
下面小編就為大家分享一篇使用pandas中的DataFrame數(shù)據(jù)繪制柱狀圖的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-04-04
Python?matplotlib數(shù)據(jù)可視化圖繪制
這篇文章主要介紹了Python?matplotlib數(shù)據(jù)可視化圖繪制,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的朋友可以參考一下2022-07-07

