本文介绍了如何查看matplotlib中可用的所有颜色图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一个函数调用可以为我提供 matplotlib 中所有可用颜色图的名称?

I was wondering if there is a function call that can give me the name of all colormaps available in matplotlib?

它曾经是可能的(参见此处):

It used to be possible by something along the lines of (see here):

import matplotlib.pyplot as plt
cmaps = sorted(m for m in plt.cm.datad if not m.endswith("_r"))

但是在 mpl 1.5 中运行它不会返回新的颜色图,例如 viridismagma 等.在新的参考页面上,代码实际上对名称进行了硬编码(参见 此处),但我想知道如果仍然可以进行与上述类似的查询?

But running this in mpl 1.5 does not return the new colormaps, such as viridis, magma and so on. On the new reference page the code actually hardcodes the names (see here) but I was wondering if a similar query to the above is still possible?

推荐答案

plt.colormaps() 返回所有已注册颜色图的列表.来自文档:

plt.colormaps() returns a list of all registered colormaps. From the docs:

matplotlib.pyplot.colormaps()

Matplotlib 提供了许多颜色图,其他的可以使用 register_cmap() 添加.此函数记录了内置的颜色图,如果调用,还将返回所有已注册颜色图的列表.

Matplotlib provides a number of colormaps, and others can be added using register_cmap(). This function documents the built-in colormaps, and will also return a list of all registered colormaps if called.

返回的列表包括 viridismagmainfernoplasma1.5 中.0

The list this returns includes viridis, magma, inferno and plasma for me in 1.5.0

这篇关于如何查看matplotlib中可用的所有颜色图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 11:16