77"""
88
99import matplotlib .pyplot as plt
10- import matplotlib .gridspec as gridspec
1110import numpy as np
12- from itertools import product
1311
1412
1513def squiggle_xy (a , b , c , d ):
@@ -18,35 +16,23 @@ def squiggle_xy(a, b, c, d):
1816
1917
2018fig = plt .figure (figsize = (8 , 8 ))
21-
22- # gridspec inside gridspec
23- outer_grid = gridspec .GridSpec (4 , 4 , wspace = 0.0 , hspace = 0.0 )
24-
25- for i in range (16 ):
26- inner_grid = gridspec .GridSpecFromSubplotSpec (
27- 3 , 3 , subplot_spec = outer_grid [i ], wspace = 0.0 , hspace = 0.0 )
28- a = i // 4 + 1
29- b = i % 4 + 1
30- for j , (c , d ) in enumerate (product (range (1 , 4 ), repeat = 2 )):
31- ax = fig .add_subplot (inner_grid [j ])
32- ax .plot (* squiggle_xy (a , b , c , d ))
33- ax .set_xticks ([])
34- ax .set_yticks ([])
35- fig .add_subplot (ax )
36-
37- all_axes = fig .get_axes ()
19+ outer_grid = fig .add_gridspec (4 , 4 , wspace = 0 , hspace = 0 )
20+
21+ for a in range (4 ):
22+ for b in range (4 ):
23+ # gridspec inside gridspec
24+ inner_grid = outer_grid [a , b ].subgridspec (3 , 3 , wspace = 0 , hspace = 0 )
25+ for c in range (3 ):
26+ for d in range (3 ):
27+ ax = fig .add_subplot (inner_grid [c , d ])
28+ ax .plot (* squiggle_xy (a + 1 , b + 1 , c + 1 , d + 1 ))
29+ ax .set (xticks = [], yticks = [])
3830
3931# 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 )
32+ for ax in fig .get_axes ():
33+ ax .spines ['top' ].set_visible (ax .is_first_row ())
34+ ax .spines ['bottom' ].set_visible (ax .is_last_row ())
35+ ax .spines ['left' ].set_visible (ax .is_first_col ())
36+ ax .spines ['right' ].set_visible (ax .is_last_col ())
5137
5238plt .show ()
0 commit comments