[matplotlib-devel] Patch/fix for two legend oddities/bugs
I noticed some odd behavior in the legend and managed to track down the source of the problem and make a fix (a diff against the current svn is attached). Specifically, two things were fixed: *The markerscale argument for the legend seems to do nothing... The attached diff properly applies the markerscale scaling for polygon/circle collections and the markers for lines with markers (but NOT patches or the width of lines elements in the legend). *If the scatterpoints argument was 3, all points beyond 3 disappeared. This was because the default scatteryoffset only had 3 entries, so if you didn't specifically overwrite this, the points beyond 3 didn't appear. I've re-worked this so that now the default properly deals with a number of points other than 3. Index: lib/matplotlib/legend.py === --- lib/matplotlib/legend.py (revision 8396) +++ lib/matplotlib/legend.py (working copy) @@ -253,7 +253,15 @@ # introduce y-offset for handles of the scatter plot if scatteryoffsets is None: -self._scatteryoffsets = np.array([3./8., 4./8., 2.5/8.]) +if scatterpoints2: +self._scatteryoffsets = np.array([.5]) +elif scatterpoints==2: +self._scatteryoffsets = np.array([.5,.5]) +elif scatterpoints==3: +self._scatteryoffsets = np.array([3./8., 4./8., 2.5/8.]) +else: +self._scatteryoffsets = np.ones(scatterpoints)*(3./8.) +self._scatteryoffsets[1::2] = 4./8. else: self._scatteryoffsets = np.asarray(scatteryoffsets) reps = int(self.numpoints / len(self._scatteryoffsets)) + 1 @@ -446,6 +454,7 @@ fontsize = self._fontsize +markerscale = self.markerscale # legend_box is a HPacker, horizontally packed with # columns. Each column is a VPacker, vertically packed with @@ -519,6 +528,9 @@ legline_marker.set_clip_box(None) legline_marker.set_clip_path(None) legline_marker.set_linestyle('None') +if markerscale !=1: +newsz = legline_marker.get_markersize()*markerscale +legline_marker.set_markersize(newsz) # 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. @@ -551,23 +563,20 @@ elif isinstance(handle, RegularPolyCollection): -#ydata = self._scatteryoffsets ydata = height*self._scatteryoffsets size_max, size_min = max(handle.get_sizes()),\ min(handle.get_sizes()) -# we may need to scale these sizes by markerscale -# attribute. But other handle types does not seem -# to care about this attribute and it is currently ignored. + if self.scatterpoints 4: -sizes = [.5*(size_max+size_min), size_max, - size_min] +sizes = np.array([.5*(size_max+size_min), size_max, + size_min]) else: sizes = (size_max-size_min)*np.linspace(0,1,self.scatterpoints)+size_min p = type(handle)(handle.get_numsides(), rotation=handle.get_rotation(), - sizes=sizes, + sizes=sizes*markerscale, offsets=zip(xdata_marker,ydata), transOffset=self.get_transform(), ) @@ -588,12 +597,12 @@ # attribute. But other handle types does not seem # to care about this attribute and it is currently ignored. if self.scatterpoints 4: -sizes = [.5*(size_max+size_min), size_max, - size_min] +sizes = np.array([.5*(size_max+size_min), size_max, + size_min]) else: sizes = (size_max-size_min)*np.linspace(0,1,self.scatterpoints)+size_min -p = type(handle)(sizes, +p = type(handle)(sizes*markerscale, offsets=zip(xdata_marker,ydata), transOffset=self.get_transform(), ) -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo___ Matplotlib-devel mailing
Re: [matplotlib-devel] Patch/fix for two legend oddities/bugs
Erik, Thanks for addressing this. I actually ran into this problem once a while back, but just figured that I was doing something wrong. I will check out your patch to see how well it works. Ben Root On Tue, Jun 8, 2010 at 2:16 PM, Erik Tollerud erik.tolle...@gmail.comwrote: I noticed some odd behavior in the legend and managed to track down the source of the problem and make a fix (a diff against the current svn is attached). Specifically, two things were fixed: *The markerscale argument for the legend seems to do nothing... The attached diff properly applies the markerscale scaling for polygon/circle collections and the markers for lines with markers (but NOT patches or the width of lines elements in the legend). *If the scatterpoints argument was 3, all points beyond 3 disappeared. This was because the default scatteryoffset only had 3 entries, so if you didn't specifically overwrite this, the points beyond 3 didn't appear. I've re-worked this so that now the default properly deals with a number of points other than 3. -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Building matplotlib on OS X
Hi Michael, may it be that you used different compilers for compiling your FreeType2 and your matplotlib? [CC=gcc-4.2] It's nearly impossible to tell afterwards from the libraries. I was able to compile matplotlib (not the svn though) on OS X Snow Leopard /without/ using the make.osx script. One has to apply some changes, but not large ones. John, I have the slight impression that you constantly try to ignore me, can you give a good reason, then I will be satisfied. Fixing the _png.cpp issue for libpng 1.4 would be a good start to make matplotlib compilable without the effort of make.osx. I want to add that I'm not an expert and used just standard approaches. But they worked (for me). Especially I have way to little knowledge of the implications of 64bit. Best, Friedrich -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Building matplotlib on OS X
On Tue, Jun 8, 2010 at 2:49 PM, Friedrich Romstedt friedrichromst...@gmail.com wrote: Hi Michael, may it be that you used different compilers for compiling your FreeType2 and your matplotlib? [CC=gcc-4.2] It's nearly impossible to tell afterwards from the libraries. I was able to compile matplotlib (not the svn though) on OS X Snow Leopard /without/ using the make.osx script. One has to apply some changes, but not large ones. John, I have the slight impression that you constantly try to ignore me, can you give a good reason, then I will be satisfied. Fixing the _png.cpp issue for libpng 1.4 would be a good start to make matplotlib compilable without the effort of make.osx. Sorry, I wasn't intentionally ignoring you. I don't have as much time as I'd like on the mpl mailing list so I sometimes dart in and out. If there is some thread or two or three where you would like me to comment or have some patches that need attention, please point me to them. Frequently, threads and contributions get left behind. Usually, the slight is not intentional but just due to bandwidth constraints. It happens enough that we have a FAQ :-) http://matplotlib.sourceforge.net/faq/howto_faq.html#contributing-howto JDH -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel