我能够绘制 RGB 分量some使用这个简单的 Python 脚本绘制 Matplotlib 颜色图:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
mapa = cm.get_cmap('viridis', 256)
R = []; G = []; B = []
ind = np.linspace(1,256,256)
for item in mapa.colors:
R.append(item[0])
G.append(item[1])
B.append(item[2])
plt.figure(1,figsize=(8,8))
plt.plot(ind,R,'r-')
plt.plot(ind,G,'g-')
plt.plot(ind,B,'b-')
plt.xlabel('$Colour \\ index$', fontsize=16, fontname="Times")
plt.ylabel('$RGB \\ component \\ weight$', fontsize=16, fontname="Times")
plt.show()
有一些,但不是全部。它适用于“viridis”,但不适用于臭名昭著的“jet”、“prism”或“summer”彩色贴图。发生这种情况是因为(似乎)这些地图没有“颜色”属性:
runfile('F:/Documents/Programs/Python/Colourmap_Plot.py',
wdir='F:/Documents/Programs/Python') 回溯(最近调用
最后的):
文件“F:\Documents\Programs\Python\Colourmap_Plot.py”,第 37 行,位于
对于mapa.colors中的项目:
AttributeError:“LinearSegmentedColormap”对象没有属性
'颜色'
我想知道为什么会发生这种情况。所有地图的结构不都应该相同吗?我如何区分具有“颜色”属性的地图和不具有“颜色”属性的地图?最后,如何从这些“不合格”地图之一中绘制组件?