I’m trying to do something in matplotlib that I do routinely in Mathematica, a “grid of grids” of plots.
I made a hi-res JPEG of what this looks like in Mathematica: http://is.gd/k2cXb (you may need to zoom in, but it’s definitely legible; don’t focus too much on the Mathematica code; what matters are the figures).
This is just an example for illustration. In reality, I’m interested in plotting experimental data.
In that example, I have a function called squiggle that takes 4 positive integers as arguments and produces a squiggly plot. Then I create a “grid of grids” of such plots, parametrized by row and column numbers. For example, the lower-left cell of the outer grid corresponds to a=4 and b=1. The inner grid within that cell consists of all the plots squiggle[4, 1, c, d], where c and d each range over {1, 2, 3}.
Notice in particular that the outer grid is constructed with different specs from those used in the inner grid (in this example, the outer grid has gridlines separating the cells, whereas the inner grids don’t). This is what differentiates this problem from the one of simply building one giant grid with all the figures. In particular, it is of paramount importance that the inner grids be grouped visually.
When I try to replicate this with matplotlib I get stuck at the inner level. IOW, I can make the inner grids, but I don’t know how to aggregate them into the outer grid. For example, this code produces the inner grid corresponding to a=4, b=1:
-----------------------------------------------------------------------------
import matplotlib.pyplot as plt
from numpy import arange, sin, cos, pi
from itertools import product
def squiggle_xy(a, b, c, d, i=arange(0.0, 2pi, 0.005)):
return sin(ia)cos(ib), sin(i*c)cos(id)
plt.figure(figsize=(8, 8))
a, b = 4, 1
for i, (c, d) in enumerate(product(range(1, 4), repeat=2)):
ax = plt.subplot(3, 3, i + 1)
plt.plot(*squiggle_xy(a, b, c, d))
ax.set_xticks([])
ax.set_yticks([])
plt.show()
-----------------------------------------------------------------------------
Can such a “grid of grids” be done with matplotlib? If so, could someone show me how?
Thanks!
G.