From 56f76f48031ee162bff9182c39b2ad59f2acc385 Mon Sep 17 00:00:00 2001 From: Damon McDougall Date: Tue, 18 Sep 2012 14:38:25 +0100 Subject: [PATCH 1/3] Fix overwriting suptitle --- lib/matplotlib/figure.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 798cd661fc1e..93677d0587a3 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -319,6 +319,7 @@ def __init__(self, self._hold = rcParams['axes.hold'] self.canvas = None + self._suptitle = None if subplotpars is None: subplotpars = SubplotParams() @@ -483,16 +484,19 @@ def suptitle(self, t, **kwargs): fig.suptitle('this is the figure title', fontsize=12) """ - x = kwargs.pop('x', 0.5) - y = kwargs.pop('y', 0.98) - if ('horizontalalignment' not in kwargs) and ('ha' not in kwargs): - kwargs['horizontalalignment'] = 'center' + if self._suptitle is not None: + self._suptitle.set_text(t) + else: + x = kwargs.pop('x', 0.5) + y = kwargs.pop('y', 0.98) + if ('horizontalalignment' not in kwargs) and ('ha' not in kwargs): + kwargs['horizontalalignment'] = 'center' - if ('verticalalignment' not in kwargs) and ('va' not in kwargs): - kwargs['verticalalignment'] = 'top' + if ('verticalalignment' not in kwargs) and ('va' not in kwargs): + kwargs['verticalalignment'] = 'top' - t = self.text(x, y, t, **kwargs) - return t + self._suptitle = self.text(x, y, t, **kwargs) + return self._suptitle def set_canvas(self, canvas): """ From c79fc2f9a44a0ac3e139f10442a1a3247ae69e1c Mon Sep 17 00:00:00 2001 From: Damon McDougall Date: Tue, 18 Sep 2012 15:18:58 +0100 Subject: [PATCH 2/3] Make suptitle take position on subsequent calls --- lib/matplotlib/figure.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 93677d0587a3..b9b3f2c7cb4c 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -484,17 +484,18 @@ def suptitle(self, t, **kwargs): fig.suptitle('this is the figure title', fontsize=12) """ + x = kwargs.pop('x', 0.5) + y = kwargs.pop('y', 0.98) + if ('horizontalalignment' not in kwargs) and ('ha' not in kwargs): + kwargs['horizontalalignment'] = 'center' + + if ('verticalalignment' not in kwargs) and ('va' not in kwargs): + kwargs['verticalalignment'] = 'top' + if self._suptitle is not None: self._suptitle.set_text(t) + self._suptitle.set_position((x, y)) else: - x = kwargs.pop('x', 0.5) - y = kwargs.pop('y', 0.98) - if ('horizontalalignment' not in kwargs) and ('ha' not in kwargs): - kwargs['horizontalalignment'] = 'center' - - if ('verticalalignment' not in kwargs) and ('va' not in kwargs): - kwargs['verticalalignment'] = 'top' - self._suptitle = self.text(x, y, t, **kwargs) return self._suptitle From a95243ec0539a3e12da898a55a554daa4cbfd2c5 Mon Sep 17 00:00:00 2001 From: Damon McDougall Date: Mon, 5 Nov 2012 12:25:25 -0600 Subject: [PATCH 3/3] Make suptitle kwargs persist on subsequent calls --- lib/matplotlib/figure.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index b9b3f2c7cb4c..85ab98e40fc0 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -493,10 +493,8 @@ def suptitle(self, t, **kwargs): kwargs['verticalalignment'] = 'top' if self._suptitle is not None: - self._suptitle.set_text(t) - self._suptitle.set_position((x, y)) - else: - self._suptitle = self.text(x, y, t, **kwargs) + self._suptitle.set_text('') + self._suptitle = self.text(x, y, t, **kwargs) return self._suptitle def set_canvas(self, canvas):