Python 3.x 如何解释LinearSegmentedColormap上的文档
我使用LinearSegmentedColormap获得了这个示例代码,我无法理解Python 3.x 如何解释LinearSegmentedColormap上的文档,python-3.x,matplotlib,Python 3.x,Matplotlib,我使用LinearSegmentedColormap获得了这个示例代码,我无法理解 type(cmap)给出matplotlib.colors.LinearSegmentedColormap cmap.\uuuuu dict\uuuuu给出 'name': 'jet', 'N': 256, '_rgba_bad': (0.0, 0.0, 0.0, 0.0), '_rgba_under': None, '_rgba_over': None, '_i_under': 256, '_i_
type(cmap)
给出matplotlib.colors.LinearSegmentedColormap
cmap.\uuuuu dict\uuuuu
给出
'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}
'__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)>})
而LinearSegmentedColormap.\uuu dict\uuuu
给出
'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}
'__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)>})
他在跑步吗?我想其中一个类方法正在运行,但是哪个呢?是否可以从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__
关于类
\uuuu dict\uuu
和实例\uuu dict\uuu
之间的差异的问题可能已经在或中得到了回答。在任何情况下,它们都是不同的,并且实例\uuuu dict\uuu
并不包含所有的类属性
但问题的核心似乎是找出调用类实例时会发生什么
您可以调用任何具有\uuuu call\uuu
方法的实例。在彩色贴图的情况下,对基进行子类化Colormap
有一个方法。它接受一个(列表)数字并返回一个(列表)颜色
是否可以从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__
不幸的是,情况似乎并非如此。文档中以及每个Colormap
子类中可能都应该有一个句子来解释它。欢迎对文档进行改进