Hello,

With matplotlib 1.1.1 on Gentoo I have been observing some strange
behaviour relating to ax.legend(frameon=False) and
print_figure(bbox_inches='tight'):

from matplotlib.figure import Figure
from matplotlib.artist import setp
from matplotlib.backends.backend_cairo import FigureCanvasCairo
import numpy as np

fig = Figure()
ax1 = fig.add_axes([0.1, 0.5, 0.8, 0.4])
ax2 = fig.add_axes([0.1, 0.1, 0.8, 0.4], sharex=ax1)
x = np.arange(0, 10, 0.2)
for ax, y in zip((ax1, ax2), (np.cos(x), np.sin(x))):
    ax.plot(x, y, label='A line')
    ax.spines['left'].set_visible(False)
    ax.yaxis.tick_right()

ax1.set_xlim((1,9))
ax1.legend(loc='upper left', frameon=False)

setp(ax1.xaxis.get_ticklabels(), visible=False)
FigureCanvasCairo(fig).print_figure('test.png', bbox_inches='tight')


On my system the resulting image has a large left margin.  However, if I
change frameon to True then the left margin is cropped (as expected).
Hence setting frameon=False for a legend appears to break tight bounding
boxes.

A similar situation occurs if legend().draw_frame(False) is used to hide
the legend frame.  My current work around is to use
legend().get_frame().set_visible(False) which results in the correct
bounding box.

I have also reproduced this using the AGG backend.

Regards, Freddie.

P.S. On an unrelated note are there any more performant alternatives to
bbox_inches='tight'?  It almost doubles the rendering time of some more
complex plots.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to