|
From: Lorenzo I. <lor...@gm...> - 2010-10-26 10:26:14
|
Thanks. This indeed improves the situation (and your suggestions about a for loop is appreciated). I am surprised at the fact that I have been able to generate such a plot via scripting only (well, with a lot of help from the list) by browsing the online examples and with my limited knowledge of matplotlib. Keep up the good work. Cheers Lorenzo On 10/26/2010 06:07 AM, Tony S Yu wrote: > > On Oct 25, 2010, at 12:56 PM, Lorenzo Isella wrote: > >> Dear All, >> I am aware that this question has already been asked several times on >> the mailing list, see e.g. >> >> http://bit.ly/aPzQTA >> >> However, in the following snippet, nothing I tried has been able to >> reduce the amount of white space around the figure (including toying >> around with >> >> ax = plt.axes([0.0, 0.0, 1.0, 1.0]) >> ) >> Of course, one can always resort to pdfcrop, but I believe there must be >> a better solution to resize the margins from matplotlib. >> Please see the snippet at the end of the email. >> Every suggestion is welcome. >> Cheers >> >> Lorenzo > > [cut out code snippet] > > You can always use subplots_adjust. I haven't looked into the details of your code, but it appears as though the actual plot (the actual graphics) is well within the margins of your subplot (extending the boundaries of the subplot would still leave a lot of white space). To counteract this you can use negative padding (and padding greater than 1); e.g. > > subplots_adjust(top=1, bottom=-0.2, left=-0.3, right=1.3) > > (you can add this right before "savefig".) This means that the actual boundaries of the subplot extend outside the figure (which normally have extents from 0 to 1). The above gives pretty good results. To get any better, I think you need to adjust the aspect ratio of the figure to match the plot (you can do this by creating a "figure" and passing a value for "figsize"). > > -Tony > > P.S. since you posted code, I'll offer an unsolicited suggestion. :) You can replace all your annotate commands (except for the last 2) with two short loops: > > for y in np.arange(-1.4, 1.5, 0.2): > annotate("", xy=(-pi/2., y), xytext=(-ini, y), arrowprops=dict(fc="g")) > for y in np.arange(-1.4, 1.5, 0.2): > annotate("", xy=(pi/2., y), xytext=(ini, y), arrowprops=dict(fc="g")) > |