Revision: 8916 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8916&view=rev Author: leejjoon Date: 2011-01-14 05:42:04 +0000 (Fri, 14 Jan 2011)
Log Message: ----------- add demo_gridspec06.py and update gridspec doc (original patch from Paul Ivanov) Modified Paths: -------------- trunk/matplotlib/doc/users/gridspec.rst Added Paths: ----------- trunk/matplotlib/doc/users/plotting/examples/demo_gridspec06.py Modified: trunk/matplotlib/doc/users/gridspec.rst =================================================================== --- trunk/matplotlib/doc/users/gridspec.rst 2011-01-13 19:07:12 UTC (rev 8915) +++ trunk/matplotlib/doc/users/gridspec.rst 2011-01-14 05:42:04 UTC (rev 8916) @@ -129,6 +129,16 @@ .. plot:: users/plotting/examples/demo_gridspec04.py +A Complex Nested GridSpec using SubplotSpec +=========================================== + +Here's a more sophisticated example of nested gridspec where we put +a box around each cell of the outer 4x4 grid, by hiding appropriate +spines in each of the inner 3x3 grids. :: + +.. plot:: users/plotting/examples/demo_gridspec06.py + + GridSpec with Varying Cell Sizes ================================ Added: trunk/matplotlib/doc/users/plotting/examples/demo_gridspec06.py =================================================================== --- trunk/matplotlib/doc/users/plotting/examples/demo_gridspec06.py (rev 0) +++ trunk/matplotlib/doc/users/plotting/examples/demo_gridspec06.py 2011-01-14 05:42:04 UTC (rev 8916) @@ -0,0 +1,53 @@ +import matplotlib.pyplot as plt +import matplotlib.gridspec as gridspec +import numpy as np + +try: + from itertools import product +except ImportError: + # product is new in v 2.6 + def product(*args, **kwds): + pools = map(tuple, args) * kwds.get('repeat', 1) + result = [[]] + for pool in pools: + result = [x+[y] for x in result for y in pool] + for prod in result: + yield tuple(prod) + + +def squiggle_xy(a, b, c, d, i=np.arange(0.0, 2*np.pi, 0.05)): + return np.sin(i*a)*np.cos(i*b), np.sin(i*c)*np.cos(i*d) + +f = plt.figure(figsize=(8, 8)) + +# gridspec inside gridspec +outer_grid = gridspec.GridSpec(4, 4, wspace=0.0, hspace=0.0) + +for i in xrange(16): + inner_grid = gridspec.GridSpecFromSubplotSpec(3, 3, + subplot_spec=outer_grid[i], wspace=0.0, hspace=0.0) + a, b = int(i/4)+1,i%4+1 + for j, (c, d) in enumerate(product(range(1, 4), repeat=2)): + ax = plt.Subplot(f, inner_grid[j]) + ax.plot(*squiggle_xy(a, b, c, d)) + ax.set_xticks([]) + ax.set_yticks([]) + f.add_subplot(ax) + +all_axes = f.get_axes() + +#show only the outside spines +for ax in all_axes: + for sp in ax.spines.values(): + sp.set_visible(False) + if ax.is_first_row(): + ax.spines['top'].set_visible(True) + if ax.is_last_row(): + ax.spines['bottom'].set_visible(True) + if ax.is_first_col(): + ax.spines['left'].set_visible(True) + if ax.is_last_col(): + ax.spines['right'].set_visible(True) + +plt.show() + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Protect Your Site and Customers from Malware Attacks Learn about various malware tactics and how to avoid them. Understand malware threats, the impact they can have on your business, and how you can protect your company and customers by using code signing. http://p.sf.net/sfu/oracle-sfdevnl _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins