Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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). 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).

like image 585
Learning is a mess Avatar asked Oct 28 '14 14:10

Learning is a mess


1 Answers

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)

[

like image 60
DieterDP Avatar answered Oct 24 '22 14:10

DieterDP