From: <md...@us...> - 2008-01-09 18:52:44
|
Revision: 4830 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4830&view=rev Author: mdboom Date: 2008-01-09 10:52:16 -0800 (Wed, 09 Jan 2008) Log Message: ----------- Fix legend handles. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/legend.py Modified: trunk/matplotlib/lib/matplotlib/legend.py =================================================================== --- trunk/matplotlib/lib/matplotlib/legend.py 2008-01-09 18:37:50 UTC (rev 4829) +++ trunk/matplotlib/lib/matplotlib/legend.py 2008-01-09 18:52:16 UTC (rev 4830) @@ -248,7 +248,7 @@ legline.update_from(handle) self._set_artist_props(legline) # after update legline.set_clip_box(None) - legline.set_clip_path(self.legendPatch) + legline.set_clip_path(None) legline.set_markersize(self.markerscale*legline.get_markersize()) ret.append(legline) @@ -260,14 +260,14 @@ p.update_from(handle) self._set_artist_props(p) p.set_clip_box(None) - p.set_clip_path(self.legendPatch) + p.set_clip_path(None) ret.append(p) elif isinstance(handle, LineCollection): ydata = (y-HEIGHT/2)*npy.ones(self._xdata.shape, float) legline = Line2D(self._xdata, ydata) self._set_artist_props(legline) legline.set_clip_box(None) - legline.set_clip_path(self.legendPatch) + legline.set_clip_path(None) lw = handle.get_linewidth()[0] dashes = handle.get_dashes() color = handle.get_colors()[0] @@ -285,7 +285,7 @@ p.set_edgecolor(handle._edgecolors[0]) self._set_artist_props(p) p.set_clip_box(None) - p.set_clip_path(self.legendPatch) + p.set_clip_path(None) ret.append(p) else: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-01-15 20:52:31
|
Revision: 4871 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4871&view=rev Author: mdboom Date: 2008-01-15 12:52:27 -0800 (Tue, 15 Jan 2008) Log Message: ----------- Make numpoints=1 work for legend handles. (Patch submitted by Paul Novak). Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/legend.py Modified: trunk/matplotlib/lib/matplotlib/legend.py =================================================================== --- trunk/matplotlib/lib/matplotlib/legend.py 2008-01-15 20:00:50 UTC (rev 4870) +++ trunk/matplotlib/lib/matplotlib/legend.py 2008-01-15 20:52:27 UTC (rev 4871) @@ -175,10 +175,6 @@ # make a trial box in the middle of the axes. relocate it # based on it's bbox left, top = 0.5, 0.5 - if self.numpoints == 1: - self._xdata = npy.array([left + self.handlelen*0.5]) - else: - self._xdata = npy.linspace(left, left + self.handlelen, self.numpoints) textleft = left+ self.handlelen+self.handletextsep self.texts = self._get_texts(labels, textleft, top) self.legendHandles = self._get_handles(handles, self.texts) @@ -236,15 +232,23 @@ def _get_handles(self, handles, texts): HEIGHT = self._approx_text_height() + left = 0.5 ret = [] # the returned legend lines for handle, label in zip(handles, texts): + if self.numpoints > 1: + xdata = npy.linspace(left, left + self.handlelen, self.numpoints) + elif self.numpoints == 1: + xdata = npy.linspace(left, left + self.handlelen, 2) + x, y = label.get_position() x -= self.handlelen + self.handletextsep if isinstance(handle, Line2D): - ydata = (y-HEIGHT/2)*npy.ones(self._xdata.shape, float) - legline = Line2D(self._xdata, ydata) + if self.numpoints == 1 and handle._marker != 'None': + xdata = npy.array([left + self.handlelen*0.5]) + ydata = (y-HEIGHT/2)*npy.ones(xdata.shape, float) + legline = Line2D(xdata, ydata) legline.update_from(handle) self._set_artist_props(legline) # after update legline.set_clip_box(None) @@ -253,8 +257,7 @@ ret.append(legline) elif isinstance(handle, Patch): - - p = Rectangle(xy=(min(self._xdata), y-3/4*HEIGHT), + p = Rectangle(xy=(min(xdata), y-3/4*HEIGHT), width = self.handlelen, height=HEIGHT/2, ) p.update_from(handle) @@ -263,8 +266,8 @@ p.set_clip_path(None) ret.append(p) elif isinstance(handle, LineCollection): - ydata = (y-HEIGHT/2)*npy.ones(self._xdata.shape, float) - legline = Line2D(self._xdata, ydata) + ydata = (y-HEIGHT/2)*npy.ones(xdata.shape, float) + legline = Line2D(xdata, ydata) self._set_artist_props(legline) legline.set_clip_box(None) legline.set_clip_path(None) @@ -277,7 +280,9 @@ ret.append(legline) elif isinstance(handle, RegularPolyCollection): - p = Rectangle(xy=(min(self._xdata), y-3/4*HEIGHT), + if self.numpoints == 1: + xdata = npy.array([left]) + p = Rectangle(xy=(min(xdata), y-3/4*HEIGHT), width = self.handlelen, height=HEIGHT/2, ) p.set_facecolor(handle._facecolors[0]) @@ -487,7 +492,7 @@ for handle, tup in zip(self.legendHandles, hpos): y,h = tup if isinstance(handle, Line2D): - ydata = y*npy.ones(self._xdata.shape, float) + ydata = y*npy.ones(handle.get_xdata().shape, float) handle.set_ydata(ydata+h/2) elif isinstance(handle, Rectangle): handle.set_y(y+1/4*h) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-01-16 13:04:56
|
Revision: 4872 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4872&view=rev Author: mdboom Date: 2008-01-16 05:04:50 -0800 (Wed, 16 Jan 2008) Log Message: ----------- Fix exception when plotting legend for LineCollection (Thanks to Paul Novak). Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/legend.py Modified: trunk/matplotlib/lib/matplotlib/legend.py =================================================================== --- trunk/matplotlib/lib/matplotlib/legend.py 2008-01-15 20:52:27 UTC (rev 4871) +++ trunk/matplotlib/lib/matplotlib/legend.py 2008-01-16 13:04:50 UTC (rev 4872) @@ -272,7 +272,7 @@ legline.set_clip_box(None) legline.set_clip_path(None) lw = handle.get_linewidth()[0] - dashes = handle.get_dashes() + dashes = handle.get_dashes()[0] color = handle.get_colors()[0] legline.set_color(color) legline.set_linewidth(lw) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2008-02-04 07:25:14
|
Revision: 4937 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4937&view=rev Author: efiring Date: 2008-02-03 23:25:08 -0800 (Sun, 03 Feb 2008) Log Message: ----------- Raise ValueError if legend is called with invalid numpoints (Paul Novak) Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/legend.py Modified: trunk/matplotlib/lib/matplotlib/legend.py =================================================================== --- trunk/matplotlib/lib/matplotlib/legend.py 2008-02-04 06:50:00 UTC (rev 4936) +++ trunk/matplotlib/lib/matplotlib/legend.py 2008-02-04 07:25:08 UTC (rev 4937) @@ -122,6 +122,8 @@ if value is None: value=rcParams["legend."+name] setattr(self,name,value) + if self.numpoints <= 0: + raise ValueError("numpoints must be >= 0; it was %d"% numpoints) if prop is None: self.prop=FontProperties(size=rcParams["legend.fontsize"]) else: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |