Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0728c55

Browse files
committed
added suptitle
svn path=/trunk/matplotlib/; revision=5390
1 parent c87f462 commit 0728c55

5 files changed

Lines changed: 41 additions & 4 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2006-06-04 Added a figure title command subtitle as a Figure method
2+
and pyplot command -- see examples/figure_title.py - JDH
3+
14
2008-06-02 Added support for log to hist with histtype='step' and fixed
25
a bug for log-scale stacked histograms - MM
36

examples/pylab_examples/figtext.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ def f(t):
1616
plot(t1, f(t1), 'bo', t2, f(t2), 'k')
1717
title('subplot 1')
1818
ylabel('Damped oscillation')
19-
figtitle = 'This is a somewhat long figure title'
20-
t = gcf().text(0.5, 0.95, figtitle,
21-
horizontalalignment='center',
22-
fontproperties=FontProperties(size=16))
19+
suptitle('This is a somewhat long figure title', fontsize=16)
2320

2421

2522
subplot(122)

lib/matplotlib/figure.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,35 @@ def get_window_extent(self, *args, **kwargs):
313313
'get the figure bounding box in display space; kwargs are void'
314314
return self.bbox
315315

316+
def suptitle(self, t, **kwargs):
317+
"""
318+
add a centered title to the figure
319+
320+
kwargs are matplotlib.text.Text properties. Using figure
321+
coordinates, the defaults are
322+
323+
x = 0.5
324+
y = 0.98
325+
horizontalalignment = 'center'
326+
verticalalignment = 'top'
327+
328+
The matplotlib.text.Text instance is returned
329+
330+
Example:
331+
332+
fig.subtitle('this is the figure title', fontsize=12)
333+
"""
334+
x = kwargs.pop('x', 0.5)
335+
y = kwargs.pop('y', 0.98)
336+
if ('horizontalalignment' not in kwargs) and ('ha' not in kwargs):
337+
kwargs['horizontalalignment'] = 'center'
338+
339+
if ('verticalalignment' not in kwargs) and ('va' not in kwargs):
340+
kwargs['verticalalignment'] = 'top'
341+
342+
t = self.text(x, y, t, **kwargs)
343+
return t
344+
316345
def set_canvas(self, canvas):
317346
"""
318347
Set the canvas the contains the figure

lib/matplotlib/pylab.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
subplot - make a subplot (numrows, numcols, axesnum)
7979
subplots_adjust - change the params controlling the subplot positions of current figure
8080
subplot_tool - launch the subplot configuration tool
81+
suptitle - add a figure title
8182
table - add a table to the plot
8283
text - add some text at location x,y to the current axes
8384
thetagrids - customize the radial theta grids and labels for polar

lib/matplotlib/pyplot.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,13 @@ def figtext(*args, **kwargs):
303303
if Figure.text.__doc__ is not None:
304304
figtext.__doc__ = dedent(Figure.text.__doc__)
305305

306+
def suptitle(*args, **kwargs):
307+
ret = gcf().suptitle(*args, **kwargs)
308+
draw_if_interactive()
309+
return ret
310+
if Figure.suptitle.__doc__ is not None:
311+
suptitle.__doc__ = dedent(Figure.suptitle.__doc__)
312+
306313
def figimage(*args, **kwargs):
307314
# allow callers to override the hold state by passing hold=True|False
308315
ret = gcf().figimage(*args, **kwargs)

0 commit comments

Comments
 (0)