【发布时间】:2019-08-23 06:18:01
【问题描述】:
我使用我无法理解的 LinearSegmentedColormap 获得了这个示例代码。
type(cmap) 给matplotlib.colors.LinearSegmentedColormap
cmap.__dict__给了
'name': 'jet',
'N': 256,
'_rgba_bad': (0.0, 0.0, 0.0, 0.0),
'_rgba_under': None,
'_rgba_over': None,
'_i_under': 256,
'_i_over': 257,
'_i_bad': 258,
'_isinit': False,
'colorbar_extend': False,
'_segmentdata': {'red': ((0.0, 0, 0),
(0.35, 0, 0),
(0.66, 1, 1),
(0.89, 1, 1),
(1, 0.5, 0.5)),
'green': ((0.0, 0, 0),
(0.125, 0, 0),
(0.375, 1, 1),
(0.64, 1, 1),
(0.91, 0, 0),
(1, 0, 0)),
'blue': ((0.0, 0.5, 0.5),
(0.11, 1, 1),
(0.34, 1, 1),
(0.65, 0, 0),
(1, 0, 0))},
'_gamma': 1.0}
LinearSegmentedColormap.__dict__ 给了
'__doc__': '\n Colormap objects based on lookup tables using linear segments.\n\n The lookup table is generated using linear interpolation for each\n primary color, with the 0-1 domain divided into any number of\n segments.\n ',
'__init__': <function matplotlib.colors.LinearSegmentedColormap.__init__(self, name, segmentdata, N=256, gamma=1.0)>,
'_init': <function matplotlib.colors.LinearSegmentedColormap._init(self)>,
'set_gamma': <function matplotlib.colors.LinearSegmentedColormap.set_gamma(self, gamma)>,
'from_list': <staticmethod at 0x1bc1ae2b5c0>,
'_resample': <function matplotlib.colors.LinearSegmentedColormap._resample(self, lutsize)>,
'reversed': <function matplotlib.colors.LinearSegmentedColormap.reversed(self, name=None)>})
cmap 不是LinearSegmentedColormap 的实例吗?在这种情况下,为什么它的属性和功能与LinearSegmentedColormap 类中的属性和功能不对应?
另一个问题是行时发生了什么:
colors = cmap(np.arange(cmap.N))
运行了吗?我想其中一个类方法正在运行,但是哪个?是否有可能从LinearSegmentedColormap 的文档中找出发生了什么?
from matplotlib.colors import LinearSegmentedColormap
import matplotlib as plt
import numpy as np
cmap = plt.cm.get_cmap('jet')
type(cmap)
cmap.**__dict__**
colors = cmap(np.arange(cmap.N))
LinearSegmentedColormap.__dict__
【问题讨论】:
标签: python-3.x matplotlib