The comments about scatterplot matrices inspired me to try something like that as well. Scatterplot matrices were not exactly what I was looking for, but I took the code from @tisimst's answer suggested by @lbn-plus-1 and adapted it a bit, as follows:
import itertools
import numpy as np
import matplotlib.pyplot as plt
def scatterplot_matrix(data, names=[], **kwargs):
"""Plots a pcolormesh matrix of subplots. The two first dimensions of
data are plotted as a mesh of values, one for each of the two last
dimensions of data. Data must thus be four-dimensional and results
in a matrix of pcolormesh plots with the number of rows equal to
the size of the third dimension of data and number of columns
equal to the size of the fourth dimension of data. Additional
keyword arguments are passed on to matplotlib\'s \"pcolormesh\"
command. Returns the matplotlib figure object containg the subplot
grid.
"""
assert data.ndim == 4, 'data must be 4-dimensional.'
datashape = data.shape
fig, axes = plt.subplots(nrows=datashape[2], ncols=datashape[3], figsize=(8,8))
fig.subplots_adjust(hspace=0.0, wspace=0.0)
for ax in axes.flat:
# Hide all ticks and labels
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
# Set up ticks only on one side for the "edge" subplots...
if ax.is_first_col():
ax.yaxis.set_ticks_position('left')
if ax.is_last_col():
ax.yaxis.set_ticks_position('right')
if ax.is_first_row():
ax.xaxis.set_ticks_position('top')
if ax.is_last_row():
ax.xaxis.set_ticks_position('bottom')
# Plot the data.
for ii in xrange(datashape[2]):
for jj in xrange(datashape[3]):
axes[ii,jj].pcolormesh(data[:,:,ii,jj], **kwargs)
# Label the diagonal subplots...
#if not names:
# names = ['x'+str(i) for i in range(numvars)]
#
#for i, label in enumerate(names):
# axes[i,i].annotate(label, (0.5, 0.5), xycoords='axes fraction',
# ha='center', va='center')
# Turn on the proper x or y axes ticks.
#for i, j in zip(range(numvars), itertools.cycle((-1, 0))):
# axes[j,i].xaxis.set_visible(True)
# axes[i,j].yaxis.set_visible(True)
# FIX #2: if numvars is odd, the bottom right corner plot doesn't have the
# correct axes limits, so we pull them from other axes
#if numvars%2:
# xlimits = axes[0,-1].get_xlim()
# ylimits = axes[-1,0].get_ylim()
# axes[-1,-1].set_xlim(xlimits)
# axes[-1,-1].set_ylim(ylimits)
return fig
if __name__=='__main__':
np.random.seed(1977)
data = np.random.random([10] * 4)
fig = scatterplot_matrix(data,
linestyle='none', marker='o', color='black', mfc='none')
fig.suptitle('Simple Scatterplot Matrix')
plt.show()
I saved the above module as datamatrix.py and use it as follows:
import datamatrix
import brewer2mpl
colors = brewer2mpl.get_map('RdBu', 'Diverging', 11).mpl_colormap
indicator = np.ma.masked_invalid(-np.sign(data1 - data2)) # Negated because the 'RdBu' colormap is the wrong way around
fig = datamatrix.scatterplot_matrix(indicator, cmap = colors)
plt.show()
The brewer2mpl
and color map stuff can be left out - that was just some coloring I was toying around with. It results in the following plot:

The "outer" dimensions of the matrix are the two parameters (the last two dimensions of data1
and data2
). Each of the pmeshcolor
plots inside the matrix is then an "occurrence map" somewhat similar to that in this answer, but a binary one for each of the pairs of parameters. The white lines at the bottom of some of the plots are regions of equality. The white dot in each of the upper right corners is a nan
value in the data.