SF.net SVN: matplotlib:[8318] trunk/matplotlib/lib/matplotlib/axes.py

2010-05-18 Thread leejjoon
Revision: 8318
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8318&view=rev
Author:   leejjoon
Date: 2010-05-18 17:14:40 + (Tue, 18 May 2010)

Log Message:
---
fix savefig bug

Modified Paths:
--
trunk/matplotlib/lib/matplotlib/axes.py

Modified: trunk/matplotlib/lib/matplotlib/axes.py
===
--- trunk/matplotlib/lib/matplotlib/axes.py 2010-05-17 19:03:58 UTC (rev 
8317)
+++ trunk/matplotlib/lib/matplotlib/axes.py 2010-05-18 17:14:40 UTC (rev 
8318)
@@ -8002,7 +8002,7 @@
 bb.extend([bby1, bby2])
 
 
-bb.extend([c.get_window_extent(renderer) for c in artists])
+bb.extend([c.get_window_extent(renderer) for c in artists if 
c.get_visible()])
 
 _bbox = mtransforms.Bbox.union([b for b in bb if b.width!=0 or 
b.height!=0])
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

--

___
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins


SF.net SVN: matplotlib:[8319] trunk/matplotlib/lib/matplotlib/text.py

2010-05-18 Thread leejjoon
Revision: 8319
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8319&view=rev
Author:   leejjoon
Date: 2010-05-18 17:14:45 + (Tue, 18 May 2010)

Log Message:
---
fix a bug in AnnotationBase._get_ref_xy

Modified Paths:
--
trunk/matplotlib/lib/matplotlib/text.py

Modified: trunk/matplotlib/lib/matplotlib/text.py
===
--- trunk/matplotlib/lib/matplotlib/text.py 2010-05-18 17:14:40 UTC (rev 
8318)
+++ trunk/matplotlib/lib/matplotlib/text.py 2010-05-18 17:14:45 UTC (rev 
8319)
@@ -1527,7 +1527,8 @@
 
 if isinstance(self.xycoords, tuple):
 s1, s2 = self.xycoords
-if s1.split()[0] == "offset" or s2.split()[0] == "offset":
+if (is_string_like(s1) and s1.split()[0] == "offset") \
+   or (is_string_like(s2) and s2.split()[0] == "offset"):
 raise ValueError("xycoords should not be an offset coordinate")
 x, y = self.xy
 x1, y1 = self._get_xy(renderer, x, y, s1)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

--

___
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins


SF.net SVN: matplotlib:[8320] trunk/matplotlib/lib/matplotlib

2010-05-18 Thread leejjoon
Revision: 8320
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8320&view=rev
Author:   leejjoon
Date: 2010-05-19 00:32:18 + (Wed, 19 May 2010)

Log Message:
---
merge mpl_toolkits.gridspec into the main tree

Modified Paths:
--
trunk/matplotlib/lib/matplotlib/axes.py
trunk/matplotlib/lib/matplotlib/pyplot.py

Added Paths:
---
trunk/matplotlib/lib/matplotlib/gridspec.py

Modified: trunk/matplotlib/lib/matplotlib/axes.py
===
--- trunk/matplotlib/lib/matplotlib/axes.py 2010-05-18 17:14:45 UTC (rev 
8319)
+++ trunk/matplotlib/lib/matplotlib/axes.py 2010-05-19 00:32:18 UTC (rev 
8320)
@@ -8039,6 +8039,8 @@
 triplot.__doc__ = mtri.triplot.__doc__
 
 
+from gridspec import GridSpec, SubplotSpec
+
 class SubplotBase:
 """
 Base class for subplots, which are :class:`Axes` instances with
@@ -8062,92 +8064,63 @@
 
 self.figure = fig
 
-if len(args)==1:
-s = str(args[0])
-if len(s) != 3:
-raise ValueError('Argument to subplot must be a 3 digits long')
-rows, cols, num = map(int, s)
+if len(args) == 1:
+if isinstance(args[0], SubplotSpec):
+self._subplotspec = args[0]
+
+else:
+s = str(args[0])
+if len(s) != 3:
+raise ValueError('Argument to subplot must be a 3 digits 
long')
+rows, cols, num = map(int, s)
+self._subplotspec = GridSpec(rows, cols)[num-1]
+# num - 1 for converting from matlab to python indexing
 elif len(args)==3:
 rows, cols, num = args
+if isinstance(num, tuple) and len(num) == 2:
+self._subplotspec = GridSpec(rows, cols)[num[0]-1:num[1]]
+else:
+self._subplotspec = GridSpec(rows, cols)[num-1]
+# num - 1 for converting from matlab to python indexing
 else:
 raise ValueError(  'Illegal argument to subplot')
 
 
-total = rows*cols
-num -= 1# convert from matlab to python indexing
-# ie num in range(0,total)
-if num >= total:
-raise ValueError( 'Subplot number exceeds total subplots')
-self._rows = rows
-self._cols = cols
-self._num = num
-
 self.update_params()
 
 # _axes_class is set in the subplot_class_factory
 self._axes_class.__init__(self, fig, self.figbox, **kwargs)
 
+
+
 def get_geometry(self):
 'get the subplot geometry, eg 2,2,3'
-return self._rows, self._cols, self._num+1
+rows, cols, num1, num2 = self.get_subplotspec().get_geometry()
+return rows, cols, num1+1 # for compatibility
 
 # COVERAGE NOTE: Never used internally or from examples
 def change_geometry(self, numrows, numcols, num):
 'change subplot geometry, eg. from 1,1,1 to 2,2,3'
-self._rows = numrows
-self._cols = numcols
-self._num = num-1
+self._subplotspec = GridSpec(numrows, numcols)[num-1]
 self.update_params()
 self.set_position(self.figbox)
 
+def get_subplotspec(self):
+'get the SubplotSpec instance associated with the subplot'
+return self._subplotspec
+
+def set_subplotspec(self, subplotspec):
+'set the SubplotSpec instance associated with the subplot'
+self._subplotspec = subplotspec
+
 def update_params(self):
 'update the subplot position from fig.subplotpars'
 
-rows = self._rows
-cols = self._cols
-num = self._num
+self.figbox, self.rowNum, self.colNum, self.numRows, self.numCols = \
+ self.get_subplotspec().get_position(self.figure,
+ return_all=True)
 
-pars = self.figure.subplotpars
-left = pars.left
-right = pars.right
-bottom = pars.bottom
-top = pars.top
-wspace = pars.wspace
-hspace = pars.hspace
-totWidth = right-left
-totHeight = top-bottom
 
-figH = totHeight/(rows + hspace*(rows-1))
-sepH = hspace*figH
-
-figW = totWidth/(cols + wspace*(cols-1))
-sepW = wspace*figW
-
-rowNum, colNum =  divmod(num, cols)
-
-figBottom = top - (rowNum+1)*figH - rowNum*sepH
-figLeft = left + colNum*(figW + sepW)
-
-self.figbox = mtransforms.Bbox.from_bounds(figLeft, figBottom,
-   figW, figH)
-self.rowNum = rowNum
-self.colNum = colNum
-self.numRows = rows
-self.numCols = cols
-
-if 0:
-print 'rcn', rows, cols, num
-print 'lbrt', left, bottom, right, top
-print 'self.figBottom', self.figBottom
-print 'self.figLeft', self.figLeft
- 

SF.net SVN: matplotlib:[8321] trunk/matplotlib

2010-05-18 Thread leejjoon
Revision: 8321
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8321&view=rev
Author:   leejjoon
Date: 2010-05-19 00:32:26 + (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])
+

SF.net SVN: matplotlib:[8322] trunk/matplotlib/doc/users

2010-05-18 Thread leejjoon
Revision: 8322
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8322&view=rev
Author:   leejjoon
Date: 2010-05-19 00:32:31 + (Wed, 19 May 2010)

Log Message:
---
fix a formatting issue of gridspec docs

Modified Paths:
--
trunk/matplotlib/doc/users/gridspec.rst
trunk/matplotlib/doc/users/index.rst

Modified: trunk/matplotlib/doc/users/gridspec.rst
===
--- trunk/matplotlib/doc/users/gridspec.rst 2010-05-19 00:32:26 UTC (rev 
8321)
+++ trunk/matplotlib/doc/users/gridspec.rst 2010-05-19 00:32:31 UTC (rev 
8322)
@@ -20,7 +20,7 @@
 
 
  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, ::
@@ -128,3 +128,4 @@
 
 .. plot:: users/plotting/examples/demo_gridspec04.py
 
+

Modified: trunk/matplotlib/doc/users/index.rst
===
--- trunk/matplotlib/doc/users/index.rst2010-05-19 00:32:26 UTC (rev 
8321)
+++ trunk/matplotlib/doc/users/index.rst2010-05-19 00:32:31 UTC (rev 
8322)
@@ -21,6 +21,7 @@
 index_text.rst
 image_tutorial.rst
 artists.rst
+gridspec.rst
 legend_guide.rst
 event_handling.rst
 transforms_tutorial.rst


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

--

___
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins


SF.net SVN: matplotlib:[8323] trunk/matplotlib

2010-05-18 Thread leejjoon
Revision: 8323
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8323&view=rev
Author:   leejjoon
Date: 2010-05-19 00:32:37 + (Wed, 19 May 2010)

Log Message:
---
gridspec supports grid of different cell sizes

Modified Paths:
--
trunk/matplotlib/doc/users/gridspec.rst
trunk/matplotlib/lib/matplotlib/gridspec.py

Added Paths:
---
trunk/matplotlib/doc/users/plotting/examples/demo_gridspec05.py

Modified: trunk/matplotlib/doc/users/gridspec.rst
===
--- trunk/matplotlib/doc/users/gridspec.rst 2010-05-19 00:32:31 UTC (rev 
8322)
+++ trunk/matplotlib/doc/users/gridspec.rst 2010-05-19 00:32:37 UTC (rev 
8323)
@@ -129,3 +129,23 @@
 .. plot:: users/plotting/examples/demo_gridspec04.py
 
 
+GridSpec with Varying Cell Sizes
+
+
+By default, GridSpec creates cells of equal sizes. You can adjust
+relative heights and widths of rows and columns. Note that absolute
+values are meaningless, onlt their relative ratios matter. ::
+
+  gs = gridspec.GridSpec(2, 2,
+ width_ratios=[1,2],
+ height_ratios=[4,1]
+ )
+  
+  ax1 = plt.subplot(gs[0])
+  ax2 = plt.subplot(gs[1])
+  ax3 = plt.subplot(gs[2])
+  ax4 = plt.subplot(gs[3])
+
+
+.. plot:: users/plotting/examples/demo_gridspec05.py
+

Added: trunk/matplotlib/doc/users/plotting/examples/demo_gridspec05.py
===
--- trunk/matplotlib/doc/users/plotting/examples/demo_gridspec05.py 
(rev 0)
+++ trunk/matplotlib/doc/users/plotting/examples/demo_gridspec05.py 
2010-05-19 00:32:37 UTC (rev 8323)
@@ -0,0 +1,26 @@
+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)
+
+
+
+f = plt.figure()
+
+gs = gridspec.GridSpec(2, 2,
+   width_ratios=[1,2],
+   height_ratios=[4,1]
+   )
+
+ax1 = plt.subplot(gs[0])
+ax2 = plt.subplot(gs[1])
+ax3 = plt.subplot(gs[2])
+ax4 = plt.subplot(gs[3])
+
+make_ticklabels_invisible(f)
+plt.show()
+

Modified: trunk/matplotlib/lib/matplotlib/gridspec.py
===
--- trunk/matplotlib/lib/matplotlib/gridspec.py 2010-05-19 00:32:31 UTC (rev 
8322)
+++ trunk/matplotlib/lib/matplotlib/gridspec.py 2010-05-19 00:32:37 UTC (rev 
8323)
@@ -21,95 +21,113 @@
 
 import matplotlib.transforms as mtransforms
 
+import numpy as np
 
-class GridSpec(object):
+class GridSpecBase(object):
 """
-A class that specifies the geometry of the grid that a subplot
-will be placed. 
+A base class of GridSpec that specifies the geometry of the grid
+that a subplot will be placed.
 """
+
 def __init__(self, nrows, ncols,
- left=None, bottom=None, right=None, top=None,
- wspace=None, hspace=None):
+ height_ratios=None, width_ratios=None):
 """
-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.
+The number of rows and number of columns of the grid need to
+be set. Optionally, the ratio of heights and widths of ros and
+columns can be specified.
 """
 #self.figure = figure
 self._nrows , self._ncols = nrows, ncols
-self.left=left
-self.bottom=bottom
-self.right=right
-self.top=top
-self.wspace=wspace
-self.hspace=hspace
 
+self.set_height_ratios(height_ratios)
+self.set_width_ratios(width_ratios)
+
 def get_geometry(self):
 'get the geometry of the grid, eg 2,3'
 return self._nrows, self._ncols
 
-_AllowedKeys = ["left", "bottom", "right", "top", "wspace", "hspace"]
+def get_subplot_params(self, fig=None):
+pass
 
-def update(self, **kwargs):
+def new_subplotspec(self, loc, rowspan=1, colspan=1):
 """
-Update the current values.  If any kwarg is None, default to
-the current value, if set, otherwise to rc.
+create and return a SuplotSpec instance.
 """
+loc1, loc2 = loc
+subplotspec = self[loc1:loc1+rowspan, loc2:loc2+colspan]
+return subplotspec
 
-for k, v in kwargs.items():
-if k in self._AllowedKeys:
-setattr(self, k, v)
-else:
-raise AttributeError("%s is unknown keyword" % (k,))
 
+def set_width_ratios(self, width_ratios):
+self._col_width_ratios = width_ratios
 
-from matplotli