简体   繁体   English

如何反转matplotlib pyplot pcolor cmap

[英]how to invert matplotlib pyplot pcolor cmap

To illustrate my question, I will generate a simple heatmap. 为了说明我的问题,我将生成一个简单的热图。

import matplotlib.pyplot as plt
import numpy as np

heatmap = np.asarray([[20, 0, 40],
                      [0, 40, 40],
                      [20, 40, 50]])

heatmap_plot = plt.pcolor(heatmap, cmap='RdBu', vmin=0, vmax=100)
plt.show()

This produces the following image; 这将产生以下图像;

在此处输入图片说明

Here, one can see that the lower values appear as darker red, and the larger values approach white. 在这里,可以看到较低的值显示为深红色,而较大的值接近白色。 How do i reverse this setting? 如何撤消此设置? I other words, how do I make lower values lighter shades (0 = white). 换句话说,如何使较低的值更浅(0 =白色)。 and larger values represent darker colors, in this case, red. 较大的值表示较深的颜色,在这种情况下为红色。

I couldn't seem to find any such parameter looking at the pcolor documentation . pcolor文档中似乎找不到任何这样的参数。

Just add _r to your cmap. 只需将_r添加到您的cmap中即可。 Your new cmap is RdBu_r. 您的新cmap是RdBu_r。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM