I'm a new matplotlib user on a Windows XP machine running mpl0.99.0 under
Python 2.5. I'm using the default rc file.
While reading through the excellent matplotlib "how-to" tutorial
(http://matplotlib.sourceforge.net/faq/howto_faq.html), I came across two
useful scripts: one to save a figure with a transparent background, and one
to resize axes automatically so that labels aren't cut off. I was able to
run both these examples given on the "how-to" successfully.
However, I ran into trouble when trying to combine them as follows:
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
fig = plt.figure()
ax = fig.add_subplot(111)
labels = ax.set_yticklabels(('really, really, really', 'long', 'labels'))
bboxes = 
for label in labels:
bbox = label.get_window_extent()
# the figure transform goes from relative coords->pixels and we
# want the inverse of that
bboxi = bbox.inverse_transformed(fig.transFigure)
# this is the bbox that bounds all the bboxes, again in relative
# figure coords
bbox = mtransforms.Bbox.union(bboxes)
if fig.subplotpars.left < bbox.width:
# we need to move it over
fig.subplots_adjust(left=1.1*bbox.width) # pad a little
In this case, the saved png file is transparent, but the original set of
axes, labels, and plot are visible as well (basically, I have two identical
plots shifted over one another on a transparent background).
Is there a way to suppress the original output (something akin to
"fig.canvas.erase()" or "fig.canvas.clear()", but I can't seem to figure it
out) so that the output png only shows the shifted axes and not both sets?
Thanks in advance!
View this message in context: http://old.nabble.com/Transparency-with-fig.canvas.mpl_connect-tp27724532p27724532.html
Sent from the matplotlib - users mailing list archive at Nabble.com.