Hi all,
how can I reduce the white area around the plots (several subplots) with legends outside to the right of the axes when saving it to a png-file?
pyplot.savefig('test2.png',bbox_inches='tight') shrinks the paper to axes size but cuts the legend.
Thanks in advance
Mario Mech
···
--
Dr. Mario Mech
Institute for Geophysics and Meteorology
University of Cologne
Zuelpicher Str. 49a
50674 Cologne
Germany
t: +49 (0)221 - 470 - 1776
f: +49 (0)221 - 470 - 5198
e: mech@...2927...
w: http://www.meteo.uni-koeln.de/~mmech/
The svn version has a new keyword "bbox_extra_artists", which could be used.
But, there is no easy way for the released version of matplotlib.
Below is a workaround you may use, but it's a bit complicated.
Regards,
-JJ
fig = figure(1)
ax = fig.add_subplot(111)
l1, = ax.plot([1,2,3])
leg = figlegend([l1], ["test"], 1)
def get_tightbbox(renderer):
from matplotlib.transforms import Bbox, TransformedBbox, Affine2D
bb = []
# add fig legend
bb.append(leg.legendPatch.get_window_extent())
for ax in fig.axes:
if ax.get_visible():
bb.append(ax.get_tightbbox(renderer))
_bbox = Bbox.union([b for b in bb if b.width!=0 or b.height!=0])
bbox_inches = TransformedBbox(_bbox,
Affine2D().scale(1./fig.dpi))
return bbox_inches
fig.get_tightbbox = get_tightbbox