SF.net SVN: matplotlib:[7287] trunk/matplotlib
Revision: 7287
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7287&view=rev
Author: jswhit
Date: 2009-07-23 12:10:18 + (Thu, 23 Jul 2009)
Log Message:
---
add 'interp' keyword to griddata. Can be set to 'linear' to get faster
linear interpolation using Delaunay package. Default is 'nn' (natural
neighbor).
Modified Paths:
--
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/mlab.py
Modified: trunk/matplotlib/CHANGELOG
===
--- trunk/matplotlib/CHANGELOG 2009-07-22 13:58:18 UTC (rev 7286)
+++ trunk/matplotlib/CHANGELOG 2009-07-23 12:10:18 UTC (rev 7287)
@@ -1,3 +1,7 @@
+2009-07-22 Added an 'interp' keyword to griddata so the faster linear
+ interpolation method can be chosen. Default is 'nn', so
+ default behavior (using natural neighbor method) is unchanged (JSW)
+
2009-07-22 Improved boilerplate.py so that it generates the correct
signatures for pyplot functions. - JKS
Modified: trunk/matplotlib/lib/matplotlib/mlab.py
===
--- trunk/matplotlib/lib/matplotlib/mlab.py 2009-07-22 13:58:18 UTC (rev
7286)
+++ trunk/matplotlib/lib/matplotlib/mlab.py 2009-07-23 12:10:18 UTC (rev
7287)
@@ -2621,7 +2621,7 @@
if opened:
fh.close()
-def griddata(x,y,z,xi,yi):
+def griddata(x,y,z,xi,yi,interp='nn'):
"""
``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
@@ -2633,7 +2633,8 @@
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
+If interp keyword is set to '`nn`' (default),
+uses natural neighbor interpolation based on Delaunay
triangulation. By default, this algorithm is provided by the
:mod:`matplotlib.delaunay` package, written by Robert Kern. The
triangulation algorithm in this package is known to fail on some
@@ -2646,6 +2647,14 @@
algorithm, otherwise it will use the built-in
:mod:`matplotlib.delaunay` package.
+If the interp keyword is set to '`linear`', then linear interpolation
+is used instead of natural neighbor. In this case, the output grid
+is assumed to be regular with a constant grid spacing in both the x and
+y directions. For regular grids with nonconstant grid spacing, you
+must use natural neighbor interpolation. Linear interpolation is only
valid if
+:mod:`matplotlib.delaunay` package is used - :mod:`mpl_tookits.natgrid`
+only provides natural neighbor interpolation.
+
The natgrid matplotlib toolkit can be downloaded from
http://sourceforge.net/project/showfiles.php?group_id=80706&package_id=142792
"""
@@ -2674,6 +2683,9 @@
y = y.compress(z.mask == False)
z = z.compressed()
if _use_natgrid: # use natgrid toolkit if available.
+if interp != 'nn':
+raise ValueError("only natural neighor interpolation"
+" allowed when using natgrid toolkit in griddata.")
if xi.ndim == 2:
xi = xi[0,:]
yi = yi[:,0]
@@ -2701,8 +2713,17 @@
# triangulate data
tri = delaunay.Triangulation(x,y)
# interpolate data
-interp = tri.nn_interpolator(z)
-zo = interp(xi,yi)
+if interp == 'nn':
+interp = tri.nn_interpolator(z)
+zo = interp(xi,yi)
+elif interp == 'linear':
+interp = tri.linear_interpolator(z)
+zo = interp[yi.min():yi.max():complex(0,yi.shape[0]),
+xi.min():xi.max():complex(0,xi.shape[1])]
+else:
+raise ValueError("interp keyword must be one of"
+" 'linear' (for linear interpolation) or 'nn'"
+" (for natural neighbor interpolation). Default is 'nn'.")
# 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)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
--
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
SF.net SVN: matplotlib:[7288] trunk/matplotlib
Revision: 7288
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7288&view=rev
Author: jswhit
Date: 2009-07-23 18:25:39 + (Thu, 23 Jul 2009)
Log Message:
---
check for nonuniform grid spacing when using inter='linear' in griddata.
update griddata_demo.py (negative seeds not allowed in numpy svn mtrand)
Modified Paths:
--
trunk/matplotlib/examples/pylab_examples/griddata_demo.py
trunk/matplotlib/lib/matplotlib/mlab.py
Modified: trunk/matplotlib/examples/pylab_examples/griddata_demo.py
===
--- trunk/matplotlib/examples/pylab_examples/griddata_demo.py 2009-07-23
12:10:18 UTC (rev 7287)
+++ trunk/matplotlib/examples/pylab_examples/griddata_demo.py 2009-07-23
18:25:39 UTC (rev 7288)
@@ -4,7 +4,7 @@
import numpy as np
# make up data.
#npts = int(raw_input('enter # of random points to plot:'))
-seed(-1)
+seed(0)
npts = 200
x = uniform(-2,2,npts)
y = uniform(-2,2,npts)
Modified: trunk/matplotlib/lib/matplotlib/mlab.py
===
--- trunk/matplotlib/lib/matplotlib/mlab.py 2009-07-23 12:10:18 UTC (rev
7287)
+++ trunk/matplotlib/lib/matplotlib/mlab.py 2009-07-23 18:25:39 UTC (rev
7288)
@@ -2717,6 +2717,14 @@
interp = tri.nn_interpolator(z)
zo = interp(xi,yi)
elif interp == 'linear':
+# make sure grid has constant dx, dy
+dx = xi[0,1:]-xi[0,0:-1]
+dy = yi[1:,0]-yi[0:-1,0]
+epsx = np.finfo(xi.dtype).resolution
+epsy = np.finfo(yi.dtype).resolution
+if dx.max()-dx.min() > epsx or dy.max()-dy.min() > epsy:
+raise ValueError("output grid must have constant spacing"
+ " when using interp='linear'")
interp = tri.linear_interpolator(z)
zo = interp[yi.min():yi.max():complex(0,yi.shape[0]),
xi.min():xi.max():complex(0,xi.shape[1])]
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
--
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
SF.net SVN: matplotlib:[7289] branches/mathtex
Revision: 7289
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7289&view=rev
Author: evilguru
Date: 2009-07-23 21:32:21 + (Thu, 23 Jul 2009)
Log Message:
---
Use svn:external to pull-in mathtex.
Modified Paths:
--
branches/mathtex/lib/matplotlib/sphinxext/mathmpl.py
Added Paths:
---
branches/mathtex/lib/mathtex/
Property Changed:
branches/mathtex/
Property changes on: branches/mathtex
___
Added: svn:externals
+ lib/mathtex http://mathtex.googlecode.com/svn/trunk/
Modified: branches/mathtex/lib/matplotlib/sphinxext/mathmpl.py
===
--- branches/mathtex/lib/matplotlib/sphinxext/mathmpl.py2009-07-23
18:25:39 UTC (rev 7288)
+++ branches/mathtex/lib/matplotlib/sphinxext/mathmpl.py2009-07-23
21:32:21 UTC (rev 7289)
@@ -9,10 +9,7 @@
from docutils.parsers.rst import directives
import warnings
-from matplotlib import rcParams
-from matplotlib.mathtext import MathTextParser
-rcParams['mathtext.fontset'] = 'cm'
-mathtext_parser = MathTextParser("Bitmap")
+from mathtex.mathtex_main import Mathtex
# Define LaTeX math node:
class latex_math(nodes.General, nodes.Element):
@@ -44,21 +41,18 @@
# This uses mathtext to render the expression
def latex2png(latex, filename, fontset='cm'):
latex = "$%s$" % latex
-orig_fontset = rcParams['mathtext.fontset']
-rcParams['mathtext.fontset'] = fontset
-if os.path.exists(filename):
-depth = mathtext_parser.get_depth(latex, dpi=100)
-else:
+
+m = Mathtex(latex, 'bakoma')
+
+if not os.path.exists(filename):
try:
-depth = mathtext_parser.to_png(filename, latex, dpi=100)
+ m.save(filename)
except:
warnings.warn("Could not render math expression %s" % latex,
Warning)
-depth = 0
-rcParams['mathtext.fontset'] = orig_fontset
sys.stdout.write("#")
sys.stdout.flush()
-return depth
+return m.depth
# LaTeX to HTML translation stuff:
def latex2html(node, source):
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
--
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
SF.net SVN: matplotlib:[7290] branches/mathtex/lib/mathtex/
Revision: 7290 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7290&view=rev Author: evilguru Date: 2009-07-23 21:36:51 + (Thu, 23 Jul 2009) Log Message: --- Try deleting the mathtex folder to get svn:externals working. Removed Paths: - branches/mathtex/lib/mathtex/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. -- ___ Matplotlib-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
SF.net SVN: matplotlib:[7291] trunk/matplotlib/lib/mpl_toolkits/axes_grid/ axislines.py
Revision: 7291 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7291&view=rev Author: leejjoon Date: 2009-07-23 21:59:15 + (Thu, 23 Jul 2009) Log Message: --- axes_grid: axisline respect rcParam's tick.direction Modified Paths: -- trunk/matplotlib/lib/mpl_toolkits/axes_grid/axislines.py Modified: trunk/matplotlib/lib/mpl_toolkits/axes_grid/axislines.py === --- trunk/matplotlib/lib/mpl_toolkits/axes_grid/axislines.py2009-07-23 21:36:51 UTC (rev 7290) +++ trunk/matplotlib/lib/mpl_toolkits/axes_grid/axislines.py2009-07-23 21:59:15 UTC (rev 7291) @@ -434,6 +434,13 @@ if self.passthru_pt[1 - self.nth_coord] > 0.5: angle = 180+angle + +# take care the tick direction +if self.nth_coord == 0 and rcParams["xtick.direction"] == "out": +angle += 180 +elif self.nth_coord == 1 and rcParams["ytick.direction"] == "out": +angle += 180 + major = self.axis.major majorLocs = major.locator() major.formatter.set_locs(majorLocs) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. -- ___ Matplotlib-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
SF.net SVN: matplotlib:[7292] trunk/matplotlib/lib/mpl_toolkits/axes_grid/ axislines.py
Revision: 7292
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7292&view=rev
Author: leejjoon
Date: 2009-07-23 22:23:04 + (Thu, 23 Jul 2009)
Log Message:
---
axes_grid: tick_out support for axisline.AxisArtist
Modified Paths:
--
trunk/matplotlib/lib/mpl_toolkits/axes_grid/axislines.py
Modified: trunk/matplotlib/lib/mpl_toolkits/axes_grid/axislines.py
===
--- trunk/matplotlib/lib/mpl_toolkits/axes_grid/axislines.py2009-07-23
21:59:15 UTC (rev 7291)
+++ trunk/matplotlib/lib/mpl_toolkits/axes_grid/axislines.py2009-07-23
22:23:04 UTC (rev 7292)
@@ -650,10 +650,16 @@
from matplotlib.lines import Line2D
class Ticks(Line2D):
-def __init__(self, ticksize, **kwargs):
+def __init__(self, ticksize, tick_out=False, **kwargs):
+"""
+ticksize : ticksize
+tick_out : tick is directed outside (rotated by 180 degree) if True.
default is False.
+"""
self.ticksize = ticksize
self.locs_angles = []
+self.set_tick_out(tick_out)
+
self._axis = kwargs.pop("axis", None)
if self._axis is not None:
if "color" not in kwargs:
@@ -664,7 +670,18 @@
super(Ticks, self).__init__([0.], [0.], **kwargs)
self.set_snap(True)
+def set_tick_out(self, b):
+"""
+set True if tick need to be rotated by 180 degree.
+"""
+self._tick_out = b
+def get_tick_out(self):
+"""
+Return True if the tick will be rotated by 180 degree.
+"""
+return self._tick_out
+
def get_color(self):
if self._color == 'auto':
if self._axis is not None:
@@ -735,8 +752,11 @@
offset = renderer.points_to_pixels(size)
marker_scale = Affine2D().scale(offset, offset)
+tick_out = self.get_tick_out()
for loc, angle, _ in self.locs_angles_labels:
+if tick_out:
+angle += 180
marker_rotation = Affine2D().rotate_deg(angle)
#marker_rotation.clear().rotate_deg(angle)
marker_transform = marker_scale + marker_rotation
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
--
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
SF.net SVN: matplotlib:[7293] trunk/matplotlib/lib/matplotlib/delaunay
Revision: 7293
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7293&view=rev
Author: jswhit
Date: 2009-07-24 02:09:20 + (Fri, 24 Jul 2009)
Log Message:
---
merge from scikits.delaunay trunk
Modified Paths:
--
trunk/matplotlib/lib/matplotlib/delaunay/VoronoiDiagramGenerator.cpp
trunk/matplotlib/lib/matplotlib/delaunay/__init__.py
trunk/matplotlib/lib/matplotlib/delaunay/_delaunay.cpp
trunk/matplotlib/lib/matplotlib/delaunay/triangulate.py
Modified: trunk/matplotlib/lib/matplotlib/delaunay/VoronoiDiagramGenerator.cpp
===
--- trunk/matplotlib/lib/matplotlib/delaunay/VoronoiDiagramGenerator.cpp
2009-07-23 22:23:04 UTC (rev 7292)
+++ trunk/matplotlib/lib/matplotlib/delaunay/VoronoiDiagramGenerator.cpp
2009-07-24 02:09:20 UTC (rev 7293)
@@ -12,9 +12,9 @@
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
-/*
- * This code was originally written by Stephan Fortune in C code. Shane
O'Sullivan,
- * have since modified it, encapsulating it in a C++ class and, fixing memory
leaks and
+/*
+ * This code was originally written by Stephan Fortune in C code. Shane
O'Sullivan,
+ * have since modified it, encapsulating it in a C++ class and, fixing memory
leaks and
* adding accessors to the Voronoi Edges.
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee is hereby granted, provided that this entire notice
@@ -26,7 +26,7 @@
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
-
+
/*
* Subsequently, Robert Kern modified it to yield Python objects.
* Copyright 2005 Robert Kern
@@ -78,9 +78,9 @@
nsites=numPoints;
plot = 0;
-triangulate = 0;
+triangulate = 0;
debug = 1;
-sorted = 0;
+sorted = 0;
freeinit(&sfl, sizeof (Site));
sites = (struct Site *) myalloc(nsites*sizeof( *sites));
@@ -112,9 +112,9 @@
//printf("\n%f %f\n",xValues[i],yValues[i]);
}
-
+
qsort(sites, nsites, sizeof (*sites), scomp);
-
+
siteidx = 0;
geominit();
double temp = 0;
@@ -134,9 +134,9 @@
borderMinY = minY;
borderMaxX = maxX;
borderMaxY = maxY;
+
+siteidx = 0;
-siteidx = 0;
-
voronoi(triangulate);
return true;
@@ -191,25 +191,25 @@
struct Halfedge * VoronoiDiagramGenerator::ELgethash(int b)
{
struct Halfedge *he;
-
-if(b<0 || b>=ELhashsize)
+
+if(b<0 || b>=ELhashsize)
return((struct Halfedge *) NULL);
-he = ELhash[b];
-if (he == (struct Halfedge *) NULL || he->ELedge != (struct Edge *)
DELETED )
+he = ELhash[b];
+if (he == (struct Halfedge *) NULL || he->ELedge != (struct Edge *)
DELETED )
return (he);
-
+
/* Hash table points to deleted half edge. Patch as necessary. */
ELhash[b] = (struct Halfedge *) NULL;
-if ((he -> ELrefcnt -= 1) == 0)
+if ((he -> ELrefcnt -= 1) == 0)
makefree((Freenode*)he, &hfl);
return ((struct Halfedge *) NULL);
-}
+}
struct Halfedge * VoronoiDiagramGenerator::ELleftbnd(struct Point *p)
{
int i, bucket;
struct Halfedge *he;
-
+
/* Use hash table to get close to desired halfedge */
bucket = (int)((p->x - xmin)/deltax * ELhashsize);//use the hash
function to find the place in the hash map that this HalfEdge should be
@@ -218,12 +218,12 @@
he = ELgethash(bucket);
if(he == (struct Halfedge *) NULL)//if the HE isn't found,
search backwards and forwards in the hash map for the first non-null entry
-{
+{
for(i=1; 1 ; i += 1)
-{
-if ((he=ELgethash(bucket-i)) != (struct Halfedge *) NULL)
+{
+if ((he=ELgethash(bucket-i)) != (struct Halfedge *) NULL)
break;
-if ((he=ELgethash(bucket+i)) != (struct Halfedge *) NULL)
+if ((he=ELgethash(bucket+i)) != (struct Halfedge *) NULL)
break;
};
totalsearch += i;
@@ -232,22 +232,22 @@
/* Now search linear list of halfedges for the correct one */
if (he==ELleftend || (he != ELrightend && right_of(he,p)))
{
-do
+do
{
he = he -> ELright;
} while (he!=ELrightend && right_of(he,p));//keep going right on
the list until either the end is reached, or you find the 1st edge which the
point
he = he -> ELleft;//isn't to the right of
}
else //if the point is to the left of the
HalfEdge, then search left for the HE just to the left of the point
-do
+do
{
he = he -> ELleft;
} while (he!=ELleftend && !right_of(he,p));
-
+
/* Update hash table and reference counts */
if(bucket
