Revision: 6067
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6067&view=rev
Author: efiring
Date: 2008-09-05 03:23:30 +0000 (Fri, 05 Sep 2008)
Log Message:
-----------
Improve masked array support in collections and quiver
Modified Paths:
--------------
trunk/matplotlib/examples/pylab_examples/line_collection.py
trunk/matplotlib/lib/matplotlib/collections.py
trunk/matplotlib/lib/matplotlib/quiver.py
Modified: trunk/matplotlib/examples/pylab_examples/line_collection.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/line_collection.py 2008-09-05
02:02:49 UTC (rev 6066)
+++ trunk/matplotlib/examples/pylab_examples/line_collection.py 2008-09-05
03:23:30 UTC (rev 6067)
@@ -1,33 +1,42 @@
-from pylab import *
+import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection
-from matplotlib.colors import ColorConverter
-colorConverter = ColorConverter()
+from matplotlib.colors import colorConverter
+import numpy as np
+
# In order to efficiently plot many lines in a single set of axes,
# Matplotlib has the ability to add the lines all at once. Here is a
# simple example showing how it is done.
-x = arange(200)
+x = np.arange(100)
# Here are many sets of y to plot vs x
-ys = [x+i for i in x]
+ys = x[:50, np.newaxis] + x[np.newaxis, :]
-# We need to set the plot limits, the will not autoscale
-ax = axes()
-ax.set_xlim((amin(x),amax(x)))
-ax.set_ylim((amin(amin(ys)),amax(amax(ys))))
+segs = np.zeros((50, 100, 2), float)
+segs[:,:,1] = ys
+segs[:,:,0] = x
+# Mask some values to test masked array support:
+segs = np.ma.masked_where((segs > 50) & (segs < 60), segs)
+
+# We need to set the plot limits.
+ax = plt.axes()
+ax.set_xlim(x.min(), x.max())
+ax.set_ylim(ys.min(), ys.max())
+
# colors is sequence of rgba tuples
# linestyle is a string or dash tuple. Legal string values are
# solid|dashed|dashdot|dotted. The dash tuple is (offset, onoffseq)
# where onoffseq is an even length tuple of on and off ink in points.
# If linestyle is omitted, 'solid' is used
# See matplotlib.collections.LineCollection for more information
-line_segments = LineCollection([zip(x,y) for y in ys], # Make a sequence of
x,y pairs
+line_segments = LineCollection(segs,
linewidths = (0.5,1,1.5,2),
colors = [colorConverter.to_rgba(i) \
for i in
('b','g','r','c','m','y','k')],
linestyle = 'solid')
ax.add_collection(line_segments)
-show()
+ax.set_title('Line collection with masked arrays')
+plt.show()
Modified: trunk/matplotlib/lib/matplotlib/collections.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/collections.py 2008-09-05 02:02:49 UTC
(rev 6066)
+++ trunk/matplotlib/lib/matplotlib/collections.py 2008-09-05 03:23:30 UTC
(rev 6067)
@@ -602,9 +602,13 @@
if closed:
self._paths = []
for xy in verts:
- xy = np.asarray(xy)
- if len(xy) and (xy[0] != xy[-1]).any():
- xy = np.concatenate([xy, [xy[0]]])
+ if np.ma.isMaskedArray(xy):
+ if len(xy) and (xy[0] != xy[-1]).any():
+ xy = np.ma.concatenate([xy, [xy[0]]])
+ else:
+ xy = np.asarray(xy)
+ if len(xy) and (xy[0] != xy[-1]).any():
+ xy = np.concatenate([xy, [xy[0]]])
self._paths.append(mpath.Path(xy))
else:
self._paths = [mpath.Path(xy) for xy in verts]
@@ -819,10 +823,14 @@
def set_segments(self, segments):
if segments is None: return
- segments = [np.asarray(seg, np.float_) for seg in segments]
+ _segments = []
+ for seg in segments:
+ if not np.ma.isMaskedArray(seg):
+ seg = np.asarray(seg, np.float_)
+ _segments.append(seg)
if self._uniform_offsets is not None:
- segments = self._add_offsets(segments)
- self._paths = [mpath.Path(seg) for seg in segments]
+ _segments = self._add_offsets(_segments)
+ self._paths = [mpath.Path(seg) for seg in _segments]
set_verts = set_segments # for compatibility with PolyCollection
Modified: trunk/matplotlib/lib/matplotlib/quiver.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/quiver.py 2008-09-05 02:02:49 UTC (rev
6066)
+++ trunk/matplotlib/lib/matplotlib/quiver.py 2008-09-05 03:23:30 UTC (rev
6067)
@@ -57,7 +57,7 @@
match the column and row dimensions of *U*, then *X* and *Y* will be
expanded with :func:`numpy.meshgrid`.
-*U*, *V*, *C* may be masked arrays, but masked *X*, ** are not
+*U*, *V*, *C* may be masked arrays, but masked *X*, *Y* are not
supported at present.
Keyword arguments:
@@ -334,12 +334,6 @@
def __init__(self, ax, *args, **kw):
self.ax = ax
X, Y, U, V, C = self._parse_args(*args)
- if C is not None:
- X, Y, U, V, C = delete_masked_points(X.ravel(),Y.ravel(),U.ravel(),
- V.ravel(),C.ravel())
- else:
- X, Y, U, V = delete_masked_points(X.ravel(),Y.ravel(),U.ravel(),
- V.ravel())
self.X = X
self.Y = Y
self.XY = np.hstack((X[:,np.newaxis], Y[:,np.newaxis]))
@@ -357,7 +351,9 @@
kw.setdefault('facecolors', self.color)
kw.setdefault('linewidths', (0,))
collections.PolyCollection.__init__(self, [], offsets=self.XY,
- transOffset=ax.transData, **kw)
+ transOffset=ax.transData,
+ closed=False,
+ **kw)
self.polykw = kw
self.set_UVC(U, V, C)
self._initialized = False
@@ -420,7 +416,7 @@
self._init()
if self._new_UV:
verts = self._make_verts(self.U, self.V)
- self.set_verts(verts)
+ self.set_verts(verts, closed=False)
self._new_UV = False
collections.PolyCollection.draw(self, renderer)
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