"John Hunter" <[EMAIL PROTECTED]> writes: > On 2/5/07, Berthold Höllmann <bhoel-lDxpuoTbsqf2eFz/[EMAIL PROTECTED]> wrote: > >> I get a file 'test.eps'. Using matplotlib 0.87.7 the PS bounding box >> of the generated plot is far to wide. Is this a problem with my script >> or a Problem of FigureCanvasAgg (and FigureCanvasPS)? What can I do to >> get a tight bounding box? > > This is a problem with the way PS computes the bounding box -- it uses > the bounding box of the Figure and ignores the fact that much of your > figure is whitespace. It should compute the bounding box of the > visible figure elements, so this should be considered a bug. To > workaround, you can set the figure size to be more like the size of > the content > > fig = Figure((3,7)) # set the width and height in inches > canvas = FigureCanvas(fig) > ax = fig.add_subplot(111) > ax.plot([.5,.7],[1.5, 2.5]) > ax.add_artist(Rectangle((.5, 1.5), .2, 1, fill=False)) > ax.set_aspect("equal") > canvas.print_figure('test.eps')
So there is no way to calculate the size occupied by the visible figure elements? In my target application I also have no easy way to figure out the size of the resulting plot, I hoped matplotlib has a way tp extract it from the plotted data. something like ----- ax.set_aspect("equal") ax.autoscale_view() w, h = fig.get_size_inches() xmin, xmax = ax.get_xlim() ymin, ymax = ax.get_ylim() xext = xmax - xmin yext = ymax - ymin if xext < yext: w = h * xext/yext else: h = w * yext/xext ----- gives a tighter bounding box, still having somehow too much room in the unchanged direction. >> Further, when I leave out the "ax.plot" line, the generated figure is >> missing the "Rectangle" and is showing only a pair of axes counting >> from 0 to 1. Is that a bug of matplotlib or something I have to fix in >> my script? > > Use add_patch instead of add_artist. add_artist is the most generic > method and Axes doesn't know how to query it's argument for it's data > limits, which it then feeds to the autoscaler. If you use add_line to > add lines.Line2D and add_patch to add patches.Patch instances, then > Axes will know how to introspect them and update the autoscaler. But > you will need to explicitly call "autoscale_view" before saving. > Something like I had tried "add_patch" but missed the ax.autoscale_view() call. Thanks Berthold -- [EMAIL PROTECTED] / <http://höllmanns.de/> [EMAIL PROTECTED] / <http://starship.python.net/crew/bhoel/> ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users