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

2008-07-21 Thread jdh2358
Revision: 5798
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5798&view=rev
Author:   jdh2358
Date: 2008-07-21 09:50:36 + (Mon, 21 Jul 2008)

Log Message:
---
Added Gael's backend fallback patch

Modified Paths:
--
trunk/matplotlib/examples/pylab_examples/scatter_demo.py
trunk/matplotlib/lib/matplotlib/backends/__init__.py
trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py
trunk/matplotlib/lib/matplotlib/pyplot.py
trunk/matplotlib/lib/matplotlib/rcsetup.py
trunk/matplotlib/matplotlibrc.template

Modified: trunk/matplotlib/examples/pylab_examples/scatter_demo.py
===
--- trunk/matplotlib/examples/pylab_examples/scatter_demo.py2008-07-21 
00:22:19 UTC (rev 5797)
+++ trunk/matplotlib/examples/pylab_examples/scatter_demo.py2008-07-21 
09:50:36 UTC (rev 5798)
@@ -6,5 +6,6 @@
 y = 0.9*rand(N)
 area = pi*(10 * rand(N))**2 # 0 to 10 point radiuses
 scatter(x,y,s=area, marker='^', c='r')
-
+savefig('test.ps')
+savefig('test.pdf')
 show()

Modified: trunk/matplotlib/lib/matplotlib/backends/__init__.py
===
--- trunk/matplotlib/lib/matplotlib/backends/__init__.py2008-07-21 
00:22:19 UTC (rev 5797)
+++ trunk/matplotlib/lib/matplotlib/backends/__init__.py2008-07-21 
09:50:36 UTC (rev 5798)
@@ -23,7 +23,9 @@
 # Things we pull in from all backends
 new_figure_manager = backend_mod.new_figure_manager
 
-
+# image backends like pdf, agg or svg do not need to do anything
+# for "show" or "draw_if_interactive", so if they are not defined
+# by the backend, just do nothing
 def do_nothing(*args, **kwargs): pass
 backend_version = getattr(backend_mod,'backend_version', 'unknown')
 show = getattr(backend_mod, 'show', do_nothing)

Modified: trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py
===
--- trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py 2008-07-21 
00:22:19 UTC (rev 5797)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py 2008-07-21 
09:50:36 UTC (rev 5798)
@@ -67,7 +67,8 @@
 for manager in Gcf.get_all_fig_managers():
 manager.window.show()
 
-if mainloop and gtk.main_level() == 0:
+if mainloop and gtk.main_level() == 0 and \
+len(Gcf.get_all_fig_managers())>0:
 gtk.main()
 
 def new_figure_manager(num, *args, **kwargs):

Modified: trunk/matplotlib/lib/matplotlib/pyplot.py
===
--- trunk/matplotlib/lib/matplotlib/pyplot.py   2008-07-21 00:22:19 UTC (rev 
5797)
+++ trunk/matplotlib/lib/matplotlib/pyplot.py   2008-07-21 09:50:36 UTC (rev 
5798)
@@ -1,12 +1,13 @@
 import sys
 
 import matplotlib
-from matplotlib import _pylab_helpers
+from matplotlib import _pylab_helpers, interactive
 from matplotlib.cbook import dedent, silent_list, is_string_like, is_numlike
 from matplotlib.figure import Figure, figaspect
 from matplotlib.backend_bases import FigureCanvasBase
 from matplotlib.image import imread as _imread
 from matplotlib import rcParams, rcParamsDefault, get_backend
+from matplotlib.rcsetup import interactive_bk as _interactive_bk
 from matplotlib.artist import getp, get, Artist
 from matplotlib.artist import setp as _setp
 from matplotlib.axes import Axes
@@ -32,7 +33,42 @@
MaxNLocator
 
 
+## Backend detection ##
+def _backend_selection():
+""" If rcParams['backend_fallback'] is true, check to see if the
+current backend is compatible with the current running event
+loop, and if not switches to a compatible one.
+"""
+backend = rcParams['backend']
+if not rcParams['backend_fallback'] or \
+ backend not in _interactive_bk:
+return
+is_agg_backend = rcParams['backend'].endswith('Agg')
+if 'wx' in sys.modules and not backend in ('WX', 'WXAgg'):
+import wx
+if wx.App.IsMainLoopRunning():
+rcParams['backend'] = 'wx' + 'Agg' * is_agg_backend
+elif 'qt' in sys.modules and not backend == 'QtAgg':
+import qt
+if not qt.qApp.startingUp():
+# The mainloop is running.
+rcParams['backend'] = 'qtAgg'
+elif 'PyQt4.QtCore' in sys.modules and not backend == 'Qt4Agg':
+import PyQt4.QtGui
+if not PyQt4.QtGui.qApp.startingUp():
+# The mainloop is running.
+rcParams['backend'] = 'qt4Agg'
+elif 'gtk' in sys.modules and not backend in ('GTK', 'GTKAgg',
+'GTKCairo'):
+import gobject
+if gobject.MainLoop().is_running():
+rcParams['backend'] = 'gtk' + 'Agg' * is_agg_backend
+elif 'Tkinter' in sys.modules and not backend == 'TkAgg':
+#import Tkinter
+pass #what if anything do we 

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

2008-07-21 Thread dmkaplan
Revision: 5799
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5799&view=rev
Author:   dmkaplan
Date: 2008-07-21 12:26:35 + (Mon, 21 Jul 2008)

Log Message:
---
Recommitting my changes to clabel to allow for manual labeling after fixing
problems with indexing identified by Eric Firing on 19 July 2008.

In addition, I have made the following changes:

1) Placed more comments in contour.py with the intention of eventually doing
a rewrite or restructuring of that code.

2) Added two pylab_examples: contour_label_demo.py that tests out some of the
more advanced things that can now be done with contour labeling, and
ginput_manual_clabel.py that demonstrates some uses of ginput,
waitforbuttonpress, and clabel(...,manual=True).  The first of these has been
integrated into backend_driver.py, but the second cannot be because it
requires interaction.

Modified Paths:
--
trunk/matplotlib/examples/tests/backend_driver.py
trunk/matplotlib/lib/matplotlib/blocking_input.py
trunk/matplotlib/lib/matplotlib/contour.py

Added Paths:
---
trunk/matplotlib/examples/pylab_examples/contour_label_demo.py
trunk/matplotlib/examples/pylab_examples/ginput_manual_clabel.py

Added: trunk/matplotlib/examples/pylab_examples/contour_label_demo.py
===
--- trunk/matplotlib/examples/pylab_examples/contour_label_demo.py  
(rev 0)
+++ trunk/matplotlib/examples/pylab_examples/contour_label_demo.py  
2008-07-21 12:26:35 UTC (rev 5799)
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+"""
+Illustrate some of the more advanced things that one can do with
+contour labels.
+
+See also contour_demo.py.
+"""
+import matplotlib
+import numpy as np
+import matplotlib.cm as cm
+import matplotlib.mlab as mlab
+import matplotlib.pyplot as plt
+
+matplotlib.rcParams['xtick.direction'] = 'out'
+matplotlib.rcParams['ytick.direction'] = 'out'
+
+##
+# Define our surface
+##
+delta = 0.025
+x = np.arange(-3.0, 3.0, delta)
+y = np.arange(-2.0, 2.0, delta)
+X, Y = np.meshgrid(x, y)
+Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
+Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
+# difference of Gaussians
+Z = 10.0 * (Z2 - Z1)
+
+##
+# Make contour labels using creative float classes
+# Follows suggestion of Manuel Metz
+##
+plt.figure()
+
+# Basic contour plot
+CS = plt.contour(X, Y, Z)
+
+# Define a class that forces representation of float to look a certain way
+# This remove trailing zero so '1.0' becomes '1'
+class nf(float):
+ def __repr__(self):
+ str = '%.1f' % (self.__float__(),)
+ if str[-1]=='0':
+ return '%.0f' % self.__float__()
+ else:
+ return '%.1f' % self.__float__()
+
+# Recast levels to new class
+CS.levels = [nf(val) for val in CS.levels ]
+
+# Label levels with specially formatted floats
+plt.clabel(CS, CS.levels, inline=True, fmt='%r %%', fontsize=10)
+
+##
+# Label contours with arbitrary strings using a
+# dictionary
+##
+plt.figure()
+
+# Basic contour plot
+CS = plt.contour(X, Y, Z)
+
+fmt = {}
+strs = [ 'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh' ]
+for l,s in zip( CS.levels, strs ):
+fmt[l] = s
+
+# Label every other level using strings
+plt.clabel(CS,CS.levels[::2],inline=True,fmt=fmt,fontsize=10)
+
+##
+# Show the hole thing
+##
+plt.show()

Added: trunk/matplotlib/examples/pylab_examples/ginput_manual_clabel.py
===
--- trunk/matplotlib/examples/pylab_examples/ginput_manual_clabel.py
(rev 0)
+++ trunk/matplotlib/examples/pylab_examples/ginput_manual_clabel.py
2008-07-21 12:26:35 UTC (rev 5799)
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+"""
+This provides examples of uses of interactive functions, such as ginput,
+waitforbuttonpress and manual clabel placement.
+
+This script must be run interactively using a backend that has a
+graphical user interface (for example, from inside ipython using
+GTKAgg backend, but not PS backend).
+"""
+import time
+import matplotlib
+import numpy as np
+import matplotlib.cm as cm
+import matplotlib.mlab as mlab
+import matplotlib.pyplot as plt
+
+def tellme(s):
+print s
+plt.title(s,fontsize=16)
+plt.draw()
+
+##
+# Define a triangle by clicking three points
+##
+plt.clf()
+plt.axis([-1.,1.,-1.,1.])
+plt.setp(plt.gca(),autoscale_on=False)
+
+tellme('You will define a triangle, click to begi

SF.net SVN: matplotlib:[5800] trunk/matplotlib/examples/pylab_examples/ ginput_manual_clabel.py

2008-07-21 Thread dmkaplan
Revision: 5800
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5800&view=rev
Author:   dmkaplan
Date: 2008-07-21 12:55:42 + (Mon, 21 Jul 2008)

Log Message:
---
Minor ginput_manual_clabel.py changes

Modified Paths:
--
trunk/matplotlib/examples/pylab_examples/ginput_manual_clabel.py

Modified: trunk/matplotlib/examples/pylab_examples/ginput_manual_clabel.py
===
--- trunk/matplotlib/examples/pylab_examples/ginput_manual_clabel.py
2008-07-21 12:26:35 UTC (rev 5799)
+++ trunk/matplotlib/examples/pylab_examples/ginput_manual_clabel.py
2008-07-21 12:55:42 UTC (rev 5800)
@@ -4,8 +4,10 @@
 waitforbuttonpress and manual clabel placement.
 
 This script must be run interactively using a backend that has a
-graphical user interface (for example, from inside ipython using
-GTKAgg backend, but not PS backend).
+graphical user interface (for example, using GTKAgg backend, but not
+PS backend).
+
+See also ginput_demo.py
 """
 import time
 import matplotlib
@@ -86,3 +88,6 @@
 
 pts = np.sort(pts,axis=0)
 plt.axis( pts.T.ravel() )
+
+tellme('All Done!')
+plt.show()


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

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins


SF.net SVN: matplotlib:[5801] trunk/matplotlib/lib/matplotlib/contour.py

2008-07-21 Thread dmkaplan
Revision: 5801
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5801&view=rev
Author:   dmkaplan
Date: 2008-07-21 12:58:53 + (Mon, 21 Jul 2008)

Log Message:
---
Fixing minor documentation problems in contour.py

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

Modified: trunk/matplotlib/lib/matplotlib/contour.py
===
--- trunk/matplotlib/lib/matplotlib/contour.py  2008-07-21 12:55:42 UTC (rev 
5800)
+++ trunk/matplotlib/lib/matplotlib/contour.py  2008-07-21 12:58:53 UTC (rev 
5801)
@@ -85,7 +85,7 @@
 
 """
 
-
+"""
 NOTES on how this all works:
 
 clabel basically takes the input arguments and uses them to
@@ -103,7 +103,7 @@
 
 Once these attributes are set, clabel passes control to the
 labels method (case of automatic label placement) or
-BlockingContourLabeler (case of manual label placement.
+BlockingContourLabeler (case of manual label placement).
 """
 
 fontsize = kwargs.get('fontsize', None)


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

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins


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

2008-07-21 Thread efiring
Revision: 5802
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5802&view=rev
Author:   efiring
Date: 2008-07-21 19:08:29 + (Mon, 21 Jul 2008)

Log Message:
---
In image.py, ensure input can be ndarray or MaskedArray (Klaus Zimmerman).
Masked 2-D arrays are handled automatically by the color mapping
framework, so they need to be passed through; but there is no
point in converting 3-D arrays into masked arrays because there
is no support for dealing with a mask in that case.

Modified Paths:
--
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/image.py

Modified: trunk/matplotlib/CHANGELOG
===
--- trunk/matplotlib/CHANGELOG  2008-07-21 12:58:53 UTC (rev 5801)
+++ trunk/matplotlib/CHANGELOG  2008-07-21 19:08:29 UTC (rev 5802)
@@ -1,3 +1,7 @@
+2008-07-21 Changed the "asarray" strategy in image.py so that
+   colormapping of masked input should work for all
+   image types (thanks Klaus Zimmerman) - EF
+
 2008-07-20 Rewrote cbook.delete_masked_points and corresponding
unit test to support rgb color array inputs, datetime
inputs, etc. - EF

Modified: trunk/matplotlib/lib/matplotlib/image.py
===
--- trunk/matplotlib/lib/matplotlib/image.py2008-07-21 12:58:53 UTC (rev 
5801)
+++ trunk/matplotlib/lib/matplotlib/image.py2008-07-21 19:08:29 UTC (rev 
5802)
@@ -272,10 +272,11 @@
 ACCEPTS: numpy/PIL Image A"""
 # check if data is PIL Image without importing Image
 if hasattr(A,'getpixel'):
-X = pil_to_array(A)
+self._A = pil_to_array(A)
+elif ma.isMA(A):
+self._A = A
 else:
-X = ma.asarray(A) # assume array
-self._A = X
+self._A = np.asarray(A) # assume array
 
 self._imcache =None
 self._rgbacache = None
@@ -408,7 +409,8 @@
 def set_data(self, x, y, A):
 x = np.asarray(x,np.float32)
 y = np.asarray(y,np.float32)
-A = np.asarray(A)
+if not ma.isMA(A):
+A = np.asarray(A)
 if len(x.shape) != 1 or len(y.shape) != 1\
or A.shape[0:2] != (y.shape[0], x.shape[0]):
 raise TypeError("Axes don't match array shape")
@@ -535,7 +537,8 @@
 
 
 def set_data(self, x, y, A):
-A = ma.asarray(A)
+if not ma.isMA(A):
+A = np.asarray(A)
 if x is None:
 x = np.arange(0, A.shape[1]+1, dtype=np.float64)
 else:


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

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins


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

2008-07-21 Thread efiring
Revision: 5803
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5803&view=rev
Author:   efiring
Date: 2008-07-21 19:39:12 + (Mon, 21 Jul 2008)

Log Message:
---
Add get_offsets, set_offsets to Collection (Ryan Kraus)

Modified Paths:
--
trunk/matplotlib/API_CHANGES
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/collections.py

Modified: trunk/matplotlib/API_CHANGES
===
--- trunk/matplotlib/API_CHANGES2008-07-21 19:08:29 UTC (rev 5802)
+++ trunk/matplotlib/API_CHANGES2008-07-21 19:39:12 UTC (rev 5803)
@@ -1,6 +1,9 @@
 Changes for 0.98.x
 ==
 
+* Methods get_offsets and set_offsets added to Collections base
+  class.
+
 * Figure.figurePatch renamed Figure.patch, Axes.axesPatch renamed
   Axes.patch, Axes.axesFrame renamed Axes.frame, Axes.get_frame, which
   returns Axes.patch, is deprecated.  Examples and users guide updated

Modified: trunk/matplotlib/CHANGELOG
===
--- trunk/matplotlib/CHANGELOG  2008-07-21 19:08:29 UTC (rev 5802)
+++ trunk/matplotlib/CHANGELOG  2008-07-21 19:39:12 UTC (rev 5803)
@@ -1,3 +1,6 @@
+2008-07-21 Committed patch by Ryan May to add get_offsets and
+   set_offsets to Collections base class - EF
+
 2008-07-21 Changed the "asarray" strategy in image.py so that
colormapping of masked input should work for all
image types (thanks Klaus Zimmerman) - EF

Modified: trunk/matplotlib/lib/matplotlib/collections.py
===
--- trunk/matplotlib/lib/matplotlib/collections.py  2008-07-21 19:08:29 UTC 
(rev 5802)
+++ trunk/matplotlib/lib/matplotlib/collections.py  2008-07-21 19:39:12 UTC 
(rev 5803)
@@ -218,6 +218,32 @@
 def set_pickradius(self,pickradius): self.pickradius = 5
 def get_pickradius(self): return self.pickradius
 
+def set_offsets(self, offsets):
+"""
+Set the offsets for the collection.  *offsets* can be a scalar
+or a sequence.
+
+ACCEPTS: float or sequence of floats
+"""
+offsets = np.asarray(offsets, np.float_)
+if len(offsets.shape) == 1:
+offsets = offsets[np.newaxis,:]  # Make it Nx2.
+#This decision is based on how they are initialized above
+if self._uniform_offsets is None:
+self._offsets = offsets
+else:
+self._uniform_offsets = offsets
+
+def get_offsets(self):
+"""
+Return the offsets for the collection.
+"""
+#This decision is based on how they are initialized above in __init__()
+if self._uniform_offsets is None:
+return self._offsets
+else:
+return self._uniform_offsets
+
 def set_linewidths(self, lw):
 """
 Set the linewidth(s) for the collection.  *lw* can be a scalar


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

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins


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

2008-07-21 Thread mdboom
Revision: 5804
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5804&view=rev
Author:   mdboom
Date: 2008-07-21 22:42:52 + (Mon, 21 Jul 2008)

Log Message:
---
Re-introduce offset_copy

Modified Paths:
--
trunk/matplotlib/API_CHANGES
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/transforms.py

Modified: trunk/matplotlib/API_CHANGES
===
--- trunk/matplotlib/API_CHANGES2008-07-21 19:39:12 UTC (rev 5803)
+++ trunk/matplotlib/API_CHANGES2008-07-21 22:42:52 UTC (rev 5804)
@@ -130,8 +130,6 @@
 
   Transform.inverse_xy_tup(points) 
Transform.inverted().transform(points)
 
-  offset_copy(trans, x, y)  trans + 
Affine2D().translate(x, y)
-
 axes.py
   Axes.get_position()  Axes.get_position()
 [Axes.get_position() used to return a list of points, not it

Modified: trunk/matplotlib/CHANGELOG
===
--- trunk/matplotlib/CHANGELOG  2008-07-21 19:39:12 UTC (rev 5803)
+++ trunk/matplotlib/CHANGELOG  2008-07-21 22:42:52 UTC (rev 5804)
@@ -1,3 +1,6 @@
+2008-07-21 Re-introduced offset_copy that works in the context of the
+   new transforms. - MGD
+
 2008-07-21 Committed patch by Ryan May to add get_offsets and
set_offsets to Collections base class - EF
 

Modified: trunk/matplotlib/lib/matplotlib/transforms.py
===
--- trunk/matplotlib/lib/matplotlib/transforms.py   2008-07-21 19:39:12 UTC 
(rev 5803)
+++ trunk/matplotlib/lib/matplotlib/transforms.py   2008-07-21 22:42:52 UTC 
(rev 5804)
@@ -2144,6 +2144,27 @@
 ((a < b) and (a < val and b > val))
 or (b < val and a > val))
 
+def offset_copy(trans, fig, x=0.0, y=0.0, units='inches'):
+'''
+Return a new transform with an added offset.
+  args:
+trans is any transform
+  kwargs:
+fig is the current figure; it can be None if units are 'dots'
+x, y give the offset
+units is 'inches', 'points' or 'dots'
+'''
+if units == 'dots':
+return trans + Affine2D().translate(x, y)
+if fig is None:
+raise ValueError('For units of inches or points a fig kwarg is needed')
+if units == 'points':
+x /= 72.0
+y /= 72.0
+elif not units == 'inches':
+raise ValueError('units must be dots, points, or inches')
+return trans + ScaledTranslation(x, y, fig.dpi_scale_trans)
+
 if __name__ == '__main__':
 import copy
 from random import random


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

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins


SF.net SVN: matplotlib:[5806] trunk/matplotlib/lib/matplotlib/mlab.py

2008-07-21 Thread jswhit
Revision: 5806
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5806&view=rev
Author:   jswhit
Date: 2008-07-22 02:17:09 + (Tue, 22 Jul 2008)

Log Message:
---
added griddata function (left out in previous commit)

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

Modified: trunk/matplotlib/lib/matplotlib/mlab.py
===
--- trunk/matplotlib/lib/matplotlib/mlab.py 2008-07-22 01:52:12 UTC (rev 
5805)
+++ trunk/matplotlib/lib/matplotlib/mlab.py 2008-07-22 02:17:09 UTC (rev 
5806)
@@ -90,6 +90,12 @@
 
 import matplotlib.nxutils as nxutils
 import matplotlib.cbook as cbook
+try:
+import mpl_tookits._natgrid as _natgrid
+_use_natgrid = True
+except ImportError:
+import matplotlib.delaunay as delaunay
+_use_natgrid = False
 
 # set is a new builtin function in 2.4; delete the following when
 # support for 2.3 is dropped.
@@ -2691,3 +2697,55 @@
  in zip(funcs, row, rowmask, mvals)])
 if opened:
 fh.close()
+
+def griddata(x,y,z,xi,yi):
+"""
+zi = griddata(x,y,z,xi,yi) fits a surface of the form z = f(x,y)
+to the data in the (usually) nonuniformly spaced vectors (x,y,z).
+griddata interpolates this surface at the points specified by (xi,yi)
+to produce zi. xi and yi must describe a regular grid, can be
+either 1D or 2D, but must be monotonically increasing.
+
+A masked array is returned if any grid points are outside convex 
+hull defined by input data (no extrapolation is done).
+
+Uses natural neighbor interpolation based on Delaunay triangulation.
+"""
+if xi.ndim != yi.ndim:
+raise TypeError("inputs xi and yi must have same number of dimensions 
(1 or 2)")
+if xi.ndim != 1 and xi.ndim != 2:
+raise TypeError("inputs xi and yi must be 1D or 2D.")
+if _use_natgrid: # use natgrid toolkit if available.
+if xi.ndim == 2:
+xi = xi[0,:]
+yi = yi[:,0]
+# override default natgrid internal parameters.
+_natgrid.seti('ext',0)
+_natgrid.setr('nul',np.nan)
+# cast input arrays to doubles (this makes a copy)
+x = x.astype(np.float)
+y = y.astype(np.float)
+z = z.astype(np.float)
+xo = xi.astype(np.float)
+yo = yi.astype(np.float)
+if min(xo[1:]-xo[0:-1]) < 0 or min(yo[1:]-yo[0:-1]) < 0:
+raise ValueError, 'output grid defined by xi,yi must be monotone 
increasing'
+# allocate array for output (buffer will be overwritten by nagridd)
+zo = np.empty((yo.shape[0],xo.shape[0]), np.float)
+_natgrid.natgridd(x,y,z,xo,yo,zo)
+else: # use Robert Kern's delaunay package from scikits (default)
+if xi.ndim != yi.ndim:
+raise TypeError("inputs xi and yi must have same number of 
dimensions (1 or 2)")
+if xi.ndim != 1 and xi.ndim != 2:
+raise TypeError("inputs xi and yi must be 1D or 2D.")
+if xi.ndim == 1:
+xi,yi = np.meshgrid(xi,yi)
+# triangulate data
+tri = delaunay.Triangulation(x,y)
+# interpolate data
+interp = tri.nn_interpolator(z)
+zo = interp(xi,yi)
+# mask points on grid outside convex hull of input data.
+if np.any(np.isnan(zo)):
+zo = np.ma.masked_where(np.isnan(zo),zo)
+return zo


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

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins


SF.net SVN: matplotlib:[5807] trunk/matplotlib/lib/matplotlib/mlab.py

2008-07-21 Thread jswhit
Revision: 5807
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5807&view=rev
Author:   jswhit
Date: 2008-07-22 02:47:02 + (Tue, 22 Jul 2008)

Log Message:
---
fix typo in as yet nonexistent natgrid import.

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

Modified: trunk/matplotlib/lib/matplotlib/mlab.py
===
--- trunk/matplotlib/lib/matplotlib/mlab.py 2008-07-22 02:17:09 UTC (rev 
5806)
+++ trunk/matplotlib/lib/matplotlib/mlab.py 2008-07-22 02:47:02 UTC (rev 
5807)
@@ -91,7 +91,7 @@
 import matplotlib.nxutils as nxutils
 import matplotlib.cbook as cbook
 try:
-import mpl_tookits._natgrid as _natgrid
+from mpl_toolkits.natgrid import _natgrid
 _use_natgrid = True
 except ImportError:
 import matplotlib.delaunay as delaunay


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

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins