如何在 matplotlib 1.4 中使用 viridis [英] How to use viridis in matplotlib 1.4

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

问题描述

我想使用颜色映射"viridis"( http://bids.github.io/colormap/),而且我还不会更新到开发版本1.5.因此,我从 https://github.com/BIDS/colormap 下载了 colormaps.py.不幸的是,我无法让它工作.这就是我要做的:

I want to use the colormap "viridis" (http://bids.github.io/colormap/), and I won't be updating to the development version 1.5 quite yet. Thus, I have downloaded colormaps.py from https://github.com/BIDS/colormap. Unfortunately, I'm not able to make it work. This is what I do:

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np

import colormaps as cmaps

img=mpimg.imread('stinkbug.png')
lum_img = np.flipud(img[:,:,0])

plt.set_cmap(cmaps.viridis)
imgplot = plt.pcolormesh(lum_img)

这给了我一个 ValueError ,回溯结束于

This gives me a ValueError, the traceback ending with,

ValueError:无法识别彩色贴图绿色.可能的值有:光谱、夏季、凉爽、...

ValueError: Colormap viridis is not recognized. Possible values are: Spectral, summer, coolwarm, ...

(然后是最初安装的颜色图的完整列表.)

(And then the complete list of originally installed colormaps.)

对如何解决此问题有任何想法吗?

Any thoughts on how to fix this issue?

推荐答案

要使用 set_cmapviridis 设置为您的颜色图,您必须先注册它:

To set viridis as your colormap using set_cmap, you must register it first:

import colormaps as cmaps
plt.register_cmap(name='viridis', cmap=cmaps.viridis)
plt.set_cmap(cmaps.viridis)

img=mpimg.imread('stinkbug.png')
lum_img = np.flipud(img[:,:,0])
imgplot = plt.pcolormesh(lum_img)

这篇关于如何在 matplotlib 1.4 中使用 viridis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆