This question relates to @bgbg's question about how to visualize only the upper or lower triangle of a symmetric matrix in matplotlib. Using his code (shown at the end), we can generate a figure like this:
Now my question: how can we draw a dark border around just this set of blocks? I ask, because I want to plot two sets of correlation data and put them next to each other as an upper and lower triangle. We can then draw a dark border around each triangle independently, to separate out the two triangles and show they are different metrics. So, like this, but not confusing:
How to do it?
#Figure 1
import numpy as NP
from matplotlib import pyplot as PLT
from matplotlib import cm as CM
A = NP.random.randint(10, 100, 100).reshape(10, 10)
mask = NP.tri(A.shape[0], k=-1)
A = NP.ma.array(A, mask=mask) # mask out the lower triangle
fig = PLT.figure()
ax1 = fig.add_subplot(111)
cmap = CM.get_cmap('jet', 10) # jet doesn't have white color
cmap.set_bad('w') # default value is 'k'
ax1.imshow(A, interpolation="nearest", cmap=cmap)
ax1.grid(True)
axis('off')
#Figure 2
A = NP.random.randint(10, 100, 100).reshape(10, 10)
mask = NP.tri(A.shape[0], k=-1)
mask = NP.zeros_like(A)
mask[NP.arange(10), NP.arange(10)] = 1
A = NP.ma.array(A, mask=mask) # mask out the lower triangle
fig = PLT.figure()
ax1 = fig.add_subplot(111)
cmap = CM.get_cmap('jet', 10) # jet doesn't have white color
cmap.set_bad('w') # default value is 'k'
ax1.imshow(A, interpolation="nearest", cmap=cmap)
title("Correlation Data 1")
ylabel("Correlation Data 2")
yticks([])
xticks([])