Skip to content

Commit 18925e5

Browse files
committed
add demo_gridspec06.py and update gridspec doc (original patch from Paul Ivanov)
svn path=/trunk/matplotlib/; revision=8916
1 parent 847874a commit 18925e5

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

doc/users/gridspec.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ parameters are set to that of the location of the given SubplotSpec. ::
129129
.. plot:: users/plotting/examples/demo_gridspec04.py
130130

131131

132+
A Complex Nested GridSpec using SubplotSpec
133+
===========================================
134+
135+
Here's a more sophisticated example of nested gridspec where we put
136+
a box around each cell of the outer 4x4 grid, by hiding appropriate
137+
spines in each of the inner 3x3 grids. ::
138+
139+
.. plot:: users/plotting/examples/demo_gridspec06.py
140+
141+
132142
GridSpec with Varying Cell Sizes
133143
================================
134144

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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

Comments
 (0)