Revision: 6127
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6127&view=rev
Author: efiring
Date: 2008-09-28 00:44:08 +0000 (Sun, 28 Sep 2008)
Log Message:
-----------
Enhancement to Axes.spy, and bugfixes:
figlegend was not plotting markers;
plot could not handle empty input arrays.
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/axes.py
trunk/matplotlib/lib/matplotlib/legend.py
trunk/matplotlib/lib/matplotlib/lines.py
trunk/matplotlib/lib/matplotlib/patches.py
trunk/matplotlib/lib/matplotlib/transforms.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2008-09-28 00:34:36 UTC (rev 6126)
+++ trunk/matplotlib/CHANGELOG 2008-09-28 00:44:08 UTC (rev 6127)
@@ -1,3 +1,7 @@
+2008-09-27 Allow spy to ignore zero values in sparse arrays, based
+ on patch by Tony Yu. Also fixed plot to handle empty
+ data arrays, and fixed handling of markers in figlegend. - EF
+
2008-09-24 Introduce drawstyles for lines. Transparently split linestyles
like 'steps--' into drawstyle 'steps' and linestyle '--'.
Legends always use drawstyle 'default'. - MM
@@ -81,7 +85,7 @@
2008-07-24 Rewrite of a significant portion of the clabel code (class
ContourLabeler) to improve inlining. - DMK
-
+
2008-07-22 Added Barbs polygon collection (similar to Quiver) for plotting
wind barbs. Added corresponding helpers to Axes and pyplot as
well. (examples/pylab_examples/barb_demo.py shows it off.) - RMM
Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py 2008-09-28 00:34:36 UTC (rev
6126)
+++ trunk/matplotlib/lib/matplotlib/axes.py 2008-09-28 00:44:08 UTC (rev
6127)
@@ -309,7 +309,8 @@
x = self.axes.convert_xunits(x)
y = self.axes.convert_yunits(y)
facecolor = self._get_next_cycle_color()
- seg = mpatches.Polygon(zip(x, y),
+ seg = mpatches.Polygon(np.hstack(
+ (x[:,np.newaxis],y[:,np.newaxis])),
facecolor = facecolor,
fill=True,
closed=closed
@@ -355,7 +356,8 @@
facecolor = color
x = self.axes.convert_xunits(x)
y = self.axes.convert_yunits(y)
- seg = mpatches.Polygon(zip(x, y),
+ seg = mpatches.Polygon(np.hstack(
+ (x[:,np.newaxis],y[:,np.newaxis])),
facecolor = facecolor,
fill=True,
closed=closed
@@ -1282,9 +1284,10 @@
line._remove_method = lambda h: self.lines.remove(h)
def _update_line_limits(self, line):
- self.dataLim.update_from_path(line.get_path(),
- self.ignore_existing_data_limits)
- self.ignore_existing_data_limits = False
+ p = line.get_path()
+ if p.vertices.size > 0:
+ self.dataLim.update_from_path(p, self.ignore_existing_data_limits)
+ self.ignore_existing_data_limits = False
def add_patch(self, p):
"""
@@ -1300,21 +1303,26 @@
self.patches.append(p)
p._remove_method = lambda h: self.patches.remove(h)
- def _update_patch_limits(self, p):
+ def _update_patch_limits(self, patch):
'update the data limits for patch *p*'
# hist can add zero height Rectangles, which is useful to keep
# the bins, counts and patches lined up, but it throws off log
# scaling. We'll ignore rects with zero height or width in
# the auto-scaling
- if isinstance(p, mpatches.Rectangle) and (p.get_width()==0. or
p.get_height()==0.):
+
+ if (isinstance(patch, mpatches.Rectangle) and
+ (patch.get_width()==0 or patch.get_height()==0)):
return
- vertices = p.get_patch_transform().transform(p.get_path().vertices)
- if p.get_data_transform() != self.transData:
- transform = p.get_data_transform() + self.transData.inverted()
- xys = transform.transform(vertices)
- # Something is wrong--xys is never used.
- self.update_datalim(vertices)
+ vertices = patch.get_path().vertices
+ if vertices.size > 0:
+ xys = patch.get_patch_transform().transform(vertices)
+ if patch.get_data_transform() != self.transData:
+ transform = (patch.get_data_transform() +
+ self.transData.inverted())
+ xys = transform.transform(xys)
+ self.update_datalim(xys)
+
def add_table(self, tab):
'''
Add a :class:`~matplotlib.tables.Table` instance to the
@@ -6645,7 +6653,7 @@
return Pxx, freqs, bins, im
def spy(self, Z, precision=None, marker=None, markersize=None,
- aspect='equal', **kwargs):
+ aspect='equal', **kwargs):
"""
call signature::
@@ -6657,6 +6665,10 @@
If *precision* is *None*, any non-zero value will be plotted;
else, values of :math:`|Z| > precision` will be plotted.
+ For :class:`scipy.sparse.spmatrix` instances, there is a
+ special case: if *precision* is 0, any value present in
+ the array will be plotted, even if it is identically zero.
+
The array will be plotted as it would be printed, with
the first index (row) increasing down and the second
index (column) increasing to the right.
@@ -6707,9 +6719,9 @@
* ',' pixel
"""
+ if marker is None and markersize is None and hasattr(Z, 'tocoo'):
+ marker = 's'
if marker is None and markersize is None:
- if hasattr(Z, 'tocoo'):
- raise TypeError, "Image mode does not support scipy.sparse
arrays"
Z = np.asarray(Z)
if precision is None: mask = Z!=0.
else: mask = np.absolute(Z)>precision
@@ -6723,23 +6735,33 @@
else:
if hasattr(Z, 'tocoo'):
c = Z.tocoo()
- y = c.row
- x = c.col
- z = c.data
+ if precision == 0:
+ y = c.row
+ x = c.col
+ else:
+ if precision is None:
+ nonzero = c.data != 0.
+ else:
+ nonzero = np.absolute(c.data) > precision
+ y = c.row[nonzero]
+ x = c.col[nonzero]
else:
Z = np.asarray(Z)
- if precision is None: mask = Z!=0.
- else: mask = np.absolute(Z)>precision
- y,x,z = mlab.get_xyz_where(mask, mask)
+ if precision is None:
+ nonzero = Z!=0.
+ else:
+ nonzero = np.absolute(Z)>precision
+ y, x = np.nonzero(nonzero)
if marker is None: marker = 's'
if markersize is None: markersize = 10
- lines = self.plot(x, y, linestyle='None',
+ marks = mlines.Line2D(x, y, linestyle='None',
marker=marker, markersize=markersize, **kwargs)
+ self.add_line(marks)
nr, nc = Z.shape
self.set_xlim(xmin=-0.5, xmax=nc-0.5)
self.set_ylim(ymin=nr-0.5, ymax=-0.5)
self.set_aspect(aspect)
- ret = lines
+ ret = marks
self.title.set_y(1.05)
self.xaxis.tick_top()
self.xaxis.set_ticks_position('both')
Modified: trunk/matplotlib/lib/matplotlib/legend.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/legend.py 2008-09-28 00:34:36 UTC (rev
6126)
+++ trunk/matplotlib/lib/matplotlib/legend.py 2008-09-28 00:44:08 UTC (rev
6127)
@@ -264,13 +264,15 @@
legline.set_clip_box(None)
legline.set_clip_path(None)
legline.set_drawstyle('default')
+ legline.set_marker('None')
ret.append(legline)
- legline.set_marker('None')
legline_marker = Line2D(xdata_marker,
ydata[:len(xdata_marker)])
legline_marker.update_from(handle)
+ self._set_artist_props(legline_marker)
+ legline_marker.set_clip_box(None)
+ legline_marker.set_clip_path(None)
legline_marker.set_linestyle('None')
- self._set_artist_props(legline_marker)
# we don't want to add this to the return list because
# the texts and handles are assumed to be in one-to-one
# correpondence.
Modified: trunk/matplotlib/lib/matplotlib/lines.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/lines.py 2008-09-28 00:34:36 UTC (rev
6126)
+++ trunk/matplotlib/lib/matplotlib/lines.py 2008-09-28 00:44:08 UTC (rev
6127)
@@ -81,14 +81,14 @@
' ' : '_draw_nothing',
'' : '_draw_nothing',
}
-
+
_drawStyles_l = {
'default' : '_draw_lines',
'steps-mid' : '_draw_steps_mid',
'steps-pre' : '_draw_steps_pre',
'steps-post' : '_draw_steps_post',
}
-
+
_drawStyles_s = {
'steps' : '_draw_steps_pre',
}
Modified: trunk/matplotlib/lib/matplotlib/patches.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/patches.py 2008-09-28 00:34:36 UTC (rev
6126)
+++ trunk/matplotlib/lib/matplotlib/patches.py 2008-09-28 00:44:08 UTC (rev
6127)
@@ -408,7 +408,7 @@
return self._rect_transform
def contains(self, mouseevent):
- # special case the degernate rectangle
+ # special case the degenerate rectangle
if self._width==0 or self._height==0:
return False, {}
Modified: trunk/matplotlib/lib/matplotlib/transforms.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/transforms.py 2008-09-28 00:34:36 UTC
(rev 6126)
+++ trunk/matplotlib/lib/matplotlib/transforms.py 2008-09-28 00:44:08 UTC
(rev 6127)
@@ -801,6 +801,9 @@
if ignore is None:
ignore = self._ignore
+ if path.vertices.size == 0:
+ return
+
points, minpos, changed = update_path_extents(
path, None, self._points, self._minpos, ignore)
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