程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How to get the color range of colomap in Python

編輯:Python

python How to take it out colomap Part of the color range

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 !


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved