matplotlib ListedColormap和LinearSegmentedColormap之间的差异[重复]

gkn4icbw  于 5个月前  发布在  其他
关注(0)|答案(2)|浏览(70)

此问题在此处已有答案

Define a colormap for each set of values in an array(1个答案)
Difference between cmap and a list of colors(2个答案)
Why the structure of Matplotlib's color maps differ?(1个答案)
28天前关闭。
我打印matplotlib颜色Map的两个类似命令,如下所示

import matplotlib as mpl
from matplotlib.colors import LinearSegmentedColormap, ListedColormap
print(mpl.colormaps['viridis'].resampled(100))
print(mpl.colormaps['copper'].resampled(100))

字符串
第一个结果是ListedColormap对象,第二个结果是LinearSegmentedColormap
我知道这两个物体之间几乎没有什么区别,但我不清楚为什么它给出了不同种类的物体。
有人能解释一下吗?

6rqinv9w

6rqinv9w1#

mpl.colormaps <$'viridis']返回ListedColormap对象:viridis是Matplotlib中存储为ListedColormap的预定义色彩Map表。ListedColormap本质上是定义色彩Map表的颜色列表。这意味着它是一个具有预定义颜色集的离散色彩Map表,并且它不会在颜色之间进行插值。当您对它重新采样时,您将获得另一个ListedColormap对象。
mpl.colormaps 'copper']返回一个LinearSegmentedColormap对象:copper是Matplotlib中另一个预定义的颜色Map表,但它被存储为LinearSegmentedColormap。LinearSegmentedColormap是一个连续的颜色Map表,可以用一组控制点来定义,允许颜色之间的插值。当你对它重新采样时,你也会得到一个LinearSegmentedColormap对象。
因此,返回的对象类型的差异是由于这些颜色Map表最初是如何定义的。viridis是离散的,而copper是连续的。当您对它们重新采样时,它们保留了其原始特征,从而导致不同类型的颜色Map表对象。

ruyhziif

ruyhziif2#

这显然是两种不同的颜色。

viridis是感知均匀色图的一部分。它被定义为listedColormap,这意味着它只是值的颜色列表。

另一方面,是顺序的,定义为LinearSegmentedColormap,允许颜色之间的平滑过渡,可以使用一组控制点进行定义
但这有什么问题?

相关问题