Description
Original report at SourceForge, opened Thu Jun 3 10:02:29 2010
The following script:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as mpl
fig = mpl.figure()
ax = fig.add_subplot(1,1,1)
ax.text(-0.2,0.5,'text',transform=ax.transAxes)
fig.savefig('test.png', bbox_inches='tight')
produces a plot where the text label does not appear. This may be due to the bounding box algorithm not taking into account text that could fall outside the Axes. One solution is to use set_xlabel and set_ylabel, for which the bounding box is correctly calculated, but in some cases it is desirable to plot labels outside the box using 'text' (for example if multiple labels are needed).
SourceForge Comments
On Thu Jun 3 11:31:16 2010, leejjoon wrote:
The currently implemented bounding box algorithm is very simple and it basically only accounts the title, axis label and ticklabels etc. I thought about implementing a general algorithm that accounts all the visible artist, but I found it very difficult (at least for me) given the support of the spline path and clipping. So, at the moment this is beyond me and I have no plan to improve it. But any contribution will be welcomed.
As a workaround, savefig can take bbox_extra_artists keyword (this may only be in the svn version though), which is a list artist that needs to be accounted for the bounding box calculation. So in your case, the below code will work.
t1 = ax.text(-0.2,0.5,'text',transform=ax.transAxes)
fig.savefig('test.png', bbox_inches='tight', bbox_extra_artists=[t1])
Given that this will not be fixed in near future and a workaround being suggested, I'm moving this to a feature request.
SourceForge History
- On Thu Jun 3 11:31:17 2010, by leejjoon: resolution_id: 100
- On Thu Jun 3 11:31:16 2010, by leejjoon: data_type: 560723