|
From: <lee...@us...> - 2010-05-19 00:32:33
|
Revision: 8321
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8321&view=rev
Author: leejjoon
Date: 2010-05-19 00:32:26 +0000 (Wed, 19 May 2010)
Log Message:
-----------
update docs. for gridspec
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
Added Paths:
-----------
trunk/matplotlib/doc/users/gridspec.rst
trunk/matplotlib/doc/users/plotting/examples/demo_gridspec01.py
trunk/matplotlib/doc/users/plotting/examples/demo_gridspec02.py
trunk/matplotlib/doc/users/plotting/examples/demo_gridspec03.py
trunk/matplotlib/doc/users/plotting/examples/demo_gridspec04.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2010-05-19 00:32:18 UTC (rev 8320)
+++ trunk/matplotlib/CHANGELOG 2010-05-19 00:32:26 UTC (rev 8321)
@@ -1,3 +1,5 @@
+2010-05-18 Merge mpl_toolkits.gridspec into the main tree. - JJL
+
2010-05-04 Improve backend_qt4 so it displays figures with the
correct size - DSD
Added: trunk/matplotlib/doc/users/gridspec.rst
===================================================================
--- trunk/matplotlib/doc/users/gridspec.rst (rev 0)
+++ trunk/matplotlib/doc/users/gridspec.rst 2010-05-19 00:32:26 UTC (rev 8321)
@@ -0,0 +1,130 @@
+.. _gridspec-guide:
+
+
+************************************************
+ Customizing Location of Subplot Using GridSpec
+************************************************
+
+ ``GridSpec``
+ specifies the geometry of the grid that a subplot will be
+ placed. The number of rows and number of columns of the grid
+ need to be set. Optionally, the subplot layout parameters
+ (e.g., left, right, etc.) can be tuned.
+
+ ``SubplotSpec``
+ specifies the location of the subplot in the given *GridSpec*.
+
+ ``subplot2grid``
+ a helper function that is similar to "pyplot.subplot" but uses
+ 0-based indexing and let subplot to occupy multiple cells.
+
+
+ Basic Example of using subplot2grid
+=====================================
+
+To use subplot2grid, you provide geometry of the grid and the location
+of the subplot in the grid. For a simple single-cell subplot, ::
+
+ ax = plt.subplot2grid((2,2),(0, 0))
+
+is identical to ::
+
+ ax = plt.subplot(2,2,1)
+
+Note that, unlike matplotlib's subplot, the index starts from 0 in gridspec.
+
+To create a subplot that spans multiple cells, ::
+
+ ax2 = plt.subplot2grid((3,3), (1, 0), colspan=2)
+ ax3 = plt.subplot2grid((3,3), (1, 2), rowspan=2)
+
+For example, the following commands ::
+
+ ax1 = plt.subplot2grid((3,3), (0,0), colspan=3)
+ ax2 = plt.subplot2grid((3,3), (1,0), colspan=2)
+ ax3 = plt.subplot2grid((3,3), (1, 2), rowspan=2)
+ ax4 = plt.subplot2grid((3,3), (2, 0))
+ ax5 = plt.subplot2grid((3,3), (2, 1))
+
+creates
+
+.. plot:: users/plotting/examples/demo_gridspec01.py
+
+
+GridSpec and SubplotSpec
+========================
+
+You can create GridSpec explicitly and use them to create a Subplot.
+
+For example, ::
+
+ ax = plt.subplot2grid((2,2),(0, 0))
+
+is equal to ::
+
+ import matplotlib.gridspec as gridspec
+ gs = gridspec.GridSpec(2, 2)
+ ax = plt.subplot(gs[0, 0])
+
+A gridspec instance provides array-like (2d or 1d) indexing that
+returns the SubplotSpec instance. For, SubplotSpec that spans multiple
+cells, use slice. ::
+
+ ax2 = plt.subplot(gs[1,:-1])
+ ax3 = plt.subplot(gs[1:, -1])
+
+The above example becomes ::
+
+ gs = gridspec.GridSpec(3, 3)
+ ax1 = plt.subplot(gs[0, :])
+ ax2 = plt.subplot(gs[1,:-1])
+ ax3 = plt.subplot(gs[1:, -1])
+ ax4 = plt.subplot(gs[-1,0])
+ ax5 = plt.subplot(gs[-1,-2])
+
+.. plot:: users/plotting/examples/demo_gridspec02.py
+
+Adjust GridSpec layout
+======================
+
+When a GridSpec is explicitly used, you can adjust the layout
+parameters of subplots that are created from the gridspec. ::
+
+ gs1 = gridspec.GridSpec(3, 3)
+ gs1.update(left=0.05, right=0.48, wspace=0.05)
+
+This is similar to *subplots_adjust*, but it only affects the subplots
+that are created from the given GridSpec.
+
+The code below ::
+
+ gs1 = gridspec.GridSpec(3, 3)
+ gs1.update(left=0.05, right=0.48, wspace=0.05)
+ ax1 = plt.subplot(gs1[:-1, :])
+ ax2 = plt.subplot(gs1[-1, :-1])
+ ax3 = plt.subplot(gs1[-1, -1])
+
+ gs2 = gridspec.GridSpec(3, 3)
+ gs2.update(left=0.55, right=0.98, hspace=0.05)
+ ax4 = plt.subplot(gs2[:, :-1])
+ ax5 = plt.subplot(gs2[:-1, -1])
+ ax6 = plt.subplot(gs2[-1, -1])
+
+creates
+
+.. plot:: users/plotting/examples/demo_gridspec03.py
+
+GridSpec using SubplotSpec
+==========================
+
+You can create GridSpec from the SubplotSpec, in which case its layout
+parameters are set to that of the locataion of the given SubplotSpec. ::
+
+ gs0 = gridspec.GridSpec(1, 2)
+
+ gs00 = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=gs0[0])
+ gs01 = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=gs0[1])
+
+
+.. plot:: users/plotting/examples/demo_gridspec04.py
+
Added: trunk/matplotlib/doc/users/plotting/examples/demo_gridspec01.py
===================================================================
--- trunk/matplotlib/doc/users/plotting/examples/demo_gridspec01.py (rev 0)
+++ trunk/matplotlib/doc/users/plotting/examples/demo_gridspec01.py 2010-05-19 00:32:26 UTC (rev 8321)
@@ -0,0 +1,20 @@
+import matplotlib.pyplot as plt
+
+def make_ticklabels_invisible(fig):
+ for i, ax in enumerate(fig.axes):
+ ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
+ for tl in ax.get_xticklabels() + ax.get_yticklabels():
+ tl.set_visible(False)
+
+
+plt.figure(0)
+ax1 = plt.subplot2grid((3,3), (0,0), colspan=3)
+ax2 = plt.subplot2grid((3,3), (1,0), colspan=2)
+ax3 = plt.subplot2grid((3,3), (1, 2), rowspan=2)
+ax4 = plt.subplot2grid((3,3), (2, 0))
+ax5 = plt.subplot2grid((3,3), (2, 1))
+
+plt.suptitle("subplot2grid")
+make_ticklabels_invisible(plt.gcf())
+plt.show()
+
Added: trunk/matplotlib/doc/users/plotting/examples/demo_gridspec02.py
===================================================================
--- trunk/matplotlib/doc/users/plotting/examples/demo_gridspec02.py (rev 0)
+++ trunk/matplotlib/doc/users/plotting/examples/demo_gridspec02.py 2010-05-19 00:32:26 UTC (rev 8321)
@@ -0,0 +1,26 @@
+import matplotlib.pyplot as plt
+from matplotlib.gridspec import GridSpec
+
+
+def make_ticklabels_invisible(fig):
+ for i, ax in enumerate(fig.axes):
+ ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
+ for tl in ax.get_xticklabels() + ax.get_yticklabels():
+ tl.set_visible(False)
+
+
+plt.figure()
+
+gs = GridSpec(3, 3)
+ax1 = plt.subplot(gs[0, :])
+# identical to ax1 = plt.subplot(gs.new_subplotspec((0,0), colspan=3))
+ax2 = plt.subplot(gs[1,:-1])
+ax3 = plt.subplot(gs[1:, -1])
+ax4 = plt.subplot(gs[-1,0])
+ax5 = plt.subplot(gs[-1,-2])
+
+plt.suptitle("GridSpec")
+make_ticklabels_invisible(plt.gcf())
+
+plt.show()
+
Added: trunk/matplotlib/doc/users/plotting/examples/demo_gridspec03.py
===================================================================
--- trunk/matplotlib/doc/users/plotting/examples/demo_gridspec03.py (rev 0)
+++ trunk/matplotlib/doc/users/plotting/examples/demo_gridspec03.py 2010-05-19 00:32:26 UTC (rev 8321)
@@ -0,0 +1,34 @@
+import matplotlib.pyplot as plt
+from matplotlib.gridspec import GridSpec
+
+
+def make_ticklabels_invisible(fig):
+ for i, ax in enumerate(fig.axes):
+ ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
+ for tl in ax.get_xticklabels() + ax.get_yticklabels():
+ tl.set_visible(False)
+
+
+
+# demo 3 : gridspec with subplotpars set.
+
+f = plt.figure()
+
+plt.suptitle("GirdSpec w/ different subplotpars")
+
+gs1 = GridSpec(3, 3)
+gs1.update(left=0.05, right=0.48, wspace=0.05)
+ax1 = plt.subplot(gs1[:-1, :])
+ax2 = plt.subplot(gs1[-1, :-1])
+ax3 = plt.subplot(gs1[-1, -1])
+
+gs2 = GridSpec(3, 3)
+gs2.update(left=0.55, right=0.98, hspace=0.05)
+ax4 = plt.subplot(gs2[:, :-1])
+ax5 = plt.subplot(gs2[:-1, -1])
+ax6 = plt.subplot(gs2[-1, -1])
+
+make_ticklabels_invisible(plt.gcf())
+
+plt.show()
+
Added: trunk/matplotlib/doc/users/plotting/examples/demo_gridspec04.py
===================================================================
--- trunk/matplotlib/doc/users/plotting/examples/demo_gridspec04.py (rev 0)
+++ trunk/matplotlib/doc/users/plotting/examples/demo_gridspec04.py 2010-05-19 00:32:26 UTC (rev 8321)
@@ -0,0 +1,41 @@
+import matplotlib.pyplot as plt
+import matplotlib.gridspec as gridspec
+
+def make_ticklabels_invisible(fig):
+ for i, ax in enumerate(fig.axes):
+ ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
+ for tl in ax.get_xticklabels() + ax.get_yticklabels():
+ tl.set_visible(False)
+
+
+
+# gridspec inside gridspec
+
+f = plt.figure()
+
+gs0 = gridspec.GridSpec(1, 2)
+
+gs00 = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=gs0[0])
+
+ax1 = plt.Subplot(f, gs00[:-1, :])
+f.add_subplot(ax1)
+ax2 = plt.Subplot(f, gs00[-1, :-1])
+f.add_subplot(ax2)
+ax3 = plt.Subplot(f, gs00[-1, -1])
+f.add_subplot(ax3)
+
+
+gs01 = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=gs0[1])
+
+ax4 = plt.Subplot(f, gs01[:, :-1])
+f.add_subplot(ax4)
+ax5 = plt.Subplot(f, gs01[:-1, -1])
+f.add_subplot(ax5)
+ax6 = plt.Subplot(f, gs01[-1, -1])
+f.add_subplot(ax6)
+
+plt.suptitle("GirdSpec Inside GridSpec")
+make_ticklabels_invisible(plt.gcf())
+
+plt.show()
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|