|
| 1 | +import matplotlib.pyplot as plt |
| 2 | +import matplotlib.gridspec as gridspec |
| 3 | +import numpy as np |
| 4 | + |
| 5 | +try: |
| 6 | + from itertools import product |
| 7 | +except ImportError: |
| 8 | + # product is new in v 2.6 |
| 9 | + def product(*args, **kwds): |
| 10 | + pools = map(tuple, args) * kwds.get('repeat', 1) |
| 11 | + result = [[]] |
| 12 | + for pool in pools: |
| 13 | + result = [x+[y] for x in result for y in pool] |
| 14 | + for prod in result: |
| 15 | + yield tuple(prod) |
| 16 | + |
| 17 | + |
| 18 | +def squiggle_xy(a, b, c, d, i=np.arange(0.0, 2*np.pi, 0.05)): |
| 19 | + return np.sin(i*a)*np.cos(i*b), np.sin(i*c)*np.cos(i*d) |
| 20 | + |
| 21 | +f = plt.figure(figsize=(8, 8)) |
| 22 | + |
| 23 | +# gridspec inside gridspec |
| 24 | +outer_grid = gridspec.GridSpec(4, 4, wspace=0.0, hspace=0.0) |
| 25 | + |
| 26 | +for i in xrange(16): |
| 27 | + inner_grid = gridspec.GridSpecFromSubplotSpec(3, 3, |
| 28 | + subplot_spec=outer_grid[i], wspace=0.0, hspace=0.0) |
| 29 | + a, b = int(i/4)+1,i%4+1 |
| 30 | + for j, (c, d) in enumerate(product(range(1, 4), repeat=2)): |
| 31 | + ax = plt.Subplot(f, inner_grid[j]) |
| 32 | + ax.plot(*squiggle_xy(a, b, c, d)) |
| 33 | + ax.set_xticks([]) |
| 34 | + ax.set_yticks([]) |
| 35 | + f.add_subplot(ax) |
| 36 | + |
| 37 | +all_axes = f.get_axes() |
| 38 | + |
| 39 | +#show only the outside spines |
| 40 | +for ax in all_axes: |
| 41 | + for sp in ax.spines.values(): |
| 42 | + sp.set_visible(False) |
| 43 | + if ax.is_first_row(): |
| 44 | + ax.spines['top'].set_visible(True) |
| 45 | + if ax.is_last_row(): |
| 46 | + ax.spines['bottom'].set_visible(True) |
| 47 | + if ax.is_first_col(): |
| 48 | + ax.spines['left'].set_visible(True) |
| 49 | + if ax.is_last_col(): |
| 50 | + ax.spines['right'].set_visible(True) |
| 51 | + |
| 52 | +plt.show() |
| 53 | + |
0 commit comments