Reputation: 22893
I want to plot something like the second following image in python using matplotlib:
The code behind this is here:
#!/usr/bin/env python
from pylab import *
Z = rand(6,10)
subplot(2,1,1)
c = pcolor(Z)
title('default: no edges')
subplot(2,1,2)
c = pcolor(Z, edgecolors='k', linewidths=4)
title('thick edges')
show()
Now, I have a list of booleans and I just want to draw a grey rectangle for each True
value and a red one for each False
value.
Say I just have this:
a = array([True,False],[False,False])
What value in [0,1] should I assign to True and to False?
Upvotes: 2
Views: 3964
Reputation: 23145
An easy way to do this is to make a custom colormap. In your case you can make a colormap with just 2 values.
from pylab import *
import matplotlib.colors
figure(figsize=(3,9))
Z = rand(6,10)
subplot(3,1,1)
c = pcolor(Z)
title('default: no edges')
subplot(3,1,2)
c = pcolor(Z, edgecolors='k', linewidths=4)
title('thick edges')
# use Z values greater than 0.5 as an example
Zbool = Z > 0.5
subplot(3,1,3)
cmap = matplotlib.colors.ListedColormap(['red','grey'])
c = pcolor(Zbool, edgecolors='k', linewidths=4, cmap=cmap)
title('thick boolean edges gray')
show()
Upvotes: 5