Paul Novak wrote: > A few weeks ago there was a discussion about putting scatter symbols in > the legend (see > http://www.nabble.com/Show-shapes-on-scatterplot-legend--to15744380.html). > > I would like to implement scatter symbols in the legend, but I am having > some problems doing so. In the function _get_handles in legend.py, the > symbol can be placed in the legend by doing something like: > > for path in handle._paths: > xy = path.vertices > p = Polygon(xy) > > The problem is that the polygon that gets drawn is the wrong size and > aspect ratio. It would seem that this would call for some sort of > scaling or transform to make the symbol the proper size, but I need some > assistance or a pointer to documentation on how to do this. > > Thanks, > > Paul Novak > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Matplotlib-devel mailing list > Matplotlib-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Hi, since I'm also very interested in this functionality I tried it myself. What I found out is the following: It appears that one transform is missing when just using the path.vertices. This is the transform that places the polygon at the correct position within the legend and scales it. Here is the code-fragment (from legend.py) that I currently use: elif isinstance(handle, RegularPolyCollection): if self.numpoints == 1: xdata = npy.array([left]) for path in handle.get_paths(): xy = path.vertices p = Polygon(xy) x = min(xdata) y = y-0.5*HEIGHT bbox = Bbox.from_bounds(x, y, HEIGHT/4., HEIGHT/4.) if 0: p = Rectangle(xy=(min(xdata), y-3/4*HEIGHT), width = self.handlelen, height=HEIGHT/2, ) p.set_facecolor(handle._facecolors[0]) if handle._edgecolors != 'None': p.set_edgecolor(handle._edgecolors[0]) self._set_artist_props(p) # HERE IS THE ADDITIONAL TRANSFORM FOR THE POLY p.set_transform( BboxTransformTo(bbox) + p.get_transform() ) p.set_clip_box(None) p.set_clip_path(None) # FOR DEBUGGING print p.get_transform() ret.append(p) This seems to works more or less, BUT NOT when rescaling the Figure Window. Then again the polygons get streched... Manuel ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel