Matplotlib 可用的内置颜色映射名称列表在哪里? 问题:
其中,matplotlib文档中列出了可用内置颜色映射名称的名称,以设置为Matplotlib 可用的内置颜色映射名称列表在哪里? 问题:,matplotlib,colors,Matplotlib,Colors,其中,matplotlib文档中列出了可用内置颜色映射名称的名称,以设置为matplotlib.cm.get\u cmap(name)中的name参数 说: Matplotlib有许多内置的颜色映射,可通过访问 说: matplotlib.cm.get\u cmap(name=None,lut=None) 获取colormap实例,如果name为None,则默认为rc值。 名称:matplotlib.colors.Colormap或str或None,默认值:None 显示多个名称 autum
matplotlib.cm.get\u cmap(name)
中的name
参数
说:
Matplotlib有许多内置的颜色映射,可通过访问
说:
matplotlib.cm.get\u cmap(name=None,lut=None)获取colormap实例,如果name为None,则默认为rc值。
- 名称:matplotlib.colors.Colormap或str或None,默认值:None
autumn sequential linearly-increasing shades of red-orange-yellow
bone sequential increasing black-white color map with a tinge of blue, to emulate X-ray film
cool linearly-decreasing shades of cyan-magenta
copper sequential increasing shades of black-copper
flag repetitive red-white-blue-black pattern (not cyclic at endpoints)
gray sequential linearly-increasing black-to-white grayscale
hot sequential black-red-yellow-white, to emulate blackbody radiation from an object at increasing temperatures
hsv cyclic red-yellow-green-cyan-blue-magenta-red, formed by changing the hue component in the HSV color space
inferno perceptually uniform shades of black-red-yellow
jet a spectral map with dark endpoints, blue-cyan-yellow-red; based on a fluid-jet simulation by NCSA [1]
magma perceptually uniform shades of black-red-white
pink sequential increasing pastel black-pink-white, meant for sepia tone colorization of photographs
plasma perceptually uniform shades of blue-red-yellow
prism repetitive red-yellow-green-blue-purple-...-green pattern (not cyclic at endpoints)
spring linearly-increasing shades of magenta-yellow
summer sequential linearly-increasing shades of green-yellow
viridis perceptually uniform shades of blue-green-yellow
winter linearly-increasing shades of blue-green
然而,简单的谷歌“matplotlib colormap names”似乎没有找到正确的文档。我假设有一个页面将名称列为枚举或常量字符串。请帮助查找。这里有一些示例代码(感谢@Patrick Fitzgerald在评论中发布了链接,因为它不像应该的那么容易找到一半),演示了如何生成带有已安装颜色贴图概述的绘图 但是,这使用了一个明确的映射列表,因此它仅限于为其编写文档的matplotlib的特定版本,因为在不同版本之间添加和删除映射。要查看您的环境到底有什么,您可以使用以下(有点粗糙的)改编版本的代码:
import numpy as np
import matplotlib.pyplot as plt
gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))
def plot_color_gradients(cmap_category, cmap_list):
# Create figure and adjust figure height to number of colormaps
nrows = len(cmap_list)
figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22
fig, axs = plt.subplots(nrows=nrows + 1, figsize=(6.4, figh))
fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh,
left=0.2, right=0.99)
axs[0].set_title(cmap_category + ' colormaps', fontsize=14)
for ax, name in zip(axs, cmap_list):
ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
ax.text(-0.01, 0.5, name, va='center', ha='right', fontsize=10,
transform=ax.transAxes)
# Turn off *all* ticks & spines, not just the ones with colormaps.
for ax in axs:
ax.set_axis_off()
cmaps = [name for name in plt.colormaps() if not name.endswith('_r')]
plot_color_gradients('all', cmaps)
plt.show()
这只绘制了所有这些,不考虑类别。
由于plt.colormaps()
生成所有贴图名称的列表,因此此版本仅删除以“\u r”
结尾的所有名称(因为这些名称是其他名称的反转版本),并将它们全部打印出来。
这仍然是一个相当长的列表,但是你可以看看,然后手动更新/删除项目从<代码> CMAPS < /代码>缩小到你将考虑的一个给定的任务。< /P>
您还可以自动将列表缩小为单色/非单色贴图,因为它们将属性作为属性提供:
cmaps_mono = [name for name in cmaps if plt.get_cmap(name).is_gray()]
cmaps_color = [name for name in cmaps if not plt.get_cmap(name).is_gray()]
这至少应该给你一个不错的起点。
如果matplotlib中有某种方法可以选择某些类型的贴图(分类、感知一致、适用于色盲观看者…),那就太好了,但我还没有找到一种方法可以自动做到这一点。您可以使用my来制作一个颜色贴图列表的简单颜色贴图概述。
在您的情况下,如果您想查看MPL中的每个颜色映射,可以使用以下选项:
将cmasher导入为cmr
将matplotlib.pyplot作为plt导入
cmr.create\u cmap\u overview(plt.colormaps(),savefig='MPL\u cmap.png')
这将为您提供在MPL中注册的所有colormaps的概览,其中包括所有内置colormaps和my CMasher软件包添加的所有colormaps,如下所示:
也许吧?你可以用。