简体   繁体   English

定义二进制 matplotlib 颜色图

[英]Defining a binary matplotlib colormap

I'm trying to use the matplotlib.imshow to plot a boolean 2d array and I'd like to be able to pick the two colours (one for true and one for false ).我正在尝试使用matplotlib.imshow来绘制一个布尔二维数组,我希望能够选择两种颜色(一种用于true ,一种用于false )。 It seems that this argument should be passed as a colormap to imshow but in my case it seems a bit of an overkill as I don't need continuous and, more important, I don't know how to define a custom colormap (the matplotlib doc hasn't helped me with that).似乎这个参数应该作为颜色图传递给imshow但在我的情况下它似乎有点矫枉过正,因为我不需要连续,更重要的是,我不知道如何定义自定义颜色图(matplotlib doc 没有帮助我)。

import matplotlib.pyplot as plt
import matplotlib.colors

# Color for False and True
cmap = matplotlib.colors.ListedColormap(['red', 'green'])

plt.imshow([True, False], [False, True]], cmap=cmap)

[

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

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