巴特的功能是非常好的。但是,如果您想自己製作色彩映射表,則可以按照在custom_cmap
example from the mpl website中完成的方式使用字典來定義像這樣的色彩映射表。
這裏的那是相當接近的顏色表的例子:
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import numpy as np
cdict = {'red': ((0.0, 0.0, 0.0), # From 0 to 0.25, we fade the red and green channels
(0.25, 0.5, 0.5), # up a little, to make the blue a bit more grey
(0.25, 0.0, 0.0), # From 0.25 to 0.75, we fade red from 0.5 to 1
(0.75, 1.0, 1.0), # to fade from green to yellow
(1.0, 0.5, 0.5)), # From 0.75 to 1.0, we bring the red down from 1
# to 0.5, to go from bright to dark red
'green': ((0.0, 0.0, 0.0), # From 0 to 0.25, we fade the red and green channels
(0.25, 0.6, 0.6), # up a little, to make the blue a bit more grey
(0.25, 1.0, 1.0), # Green is 1 from 0.25 to 0.75 (we add red
(0.75, 1.0, 1.0), # to turn it from green to yellow)
(0.75, 0.0, 0.0), # No green needed in the red upper quarter
(1.0, 0.0, 0.0)),
'blue': ((0.0, 0.9, 0.9), # Keep blue at 0.9 from 0 to 0.25, and adjust its
(0.25, 0.9, 0.9), # tone using the green and red channels
(0.25, 0.0, 0.0), # No blue needed above 0.25
(1.0, 0.0, 0.0))
}
cmap = colors.LinearSegmentedColormap('BuGnYlRd',cdict)
data = 0.9 + (np.random.rand(8,8) * 0.2) # Data in range 0.9 to 1.1
p=plt.imshow(data,interpolation='nearest',cmap=cmap,vmin=0.9,vmax=1.1)
plt.colorbar(p)
plt.show()
恐怕沒有1:1翻譯matplotlib。看看cdicts和'LinearSegmentedColormap',但是你必須使用RGB值(並且我必須承認,它並不急於理解這些cdicts)。 http://stackoverflow.com/questions/32524471/custom-colormap-in-python和http://matplotlib.org/examples/pylab_examples/custom_cmap.html –