Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib suptitle prints over old title

I am trying to use suptitle to print a title, and I want to occationally replace this title. Currently I am using:

self.ui.canvas1.figure.suptitle(title)

where figure is a matplotlib figure (canvas1 is an mplCanvas, but that is not relevant) and title is a python string.

Currently, this works, except for the fact that when I run this code again later, it just prints the new text on top of the old, resulting in a gargeled, unreadable title.

How do you replace the old suptitle of a figure, instead of just printing over?

Thanks,

Tyler

like image 825
tylerthemiler Avatar asked May 11 '12 21:05

tylerthemiler


2 Answers

figure.suptitle returns a matplotlib.text.Text instance. You can save it and set the new title:

txt = fig.suptitle('A test title')
txt.set_text('A better title')
plt.draw() 
like image 94
bmu Avatar answered Oct 22 '22 03:10

bmu


Resurrecting this old thread because I recently ran into this. There is a references to the Text object returned by the original setting of suptitle in figure.texts. You can use this to change the original until this is fixed in matplotlib.

like image 41
jseabold Avatar answered Oct 22 '22 04:10

jseabold