Reference
Add title and subtitles to a Matplotlib figure in a neat and easy way.
set_title_and_subtitle(fig, title, subtitle, alignment='left', title_size=16, subtitle_size=13, v_space=2, h_offset=2, v_offset=2)
Add title and subtitle to a Matplotlib figure. Placement is based on figure coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig |
Figure
|
Handle to the Matplotlib figure. |
required |
title |
str
|
The title. |
required |
subtitle |
str
|
The subtitle. |
required |
alignment |
str
|
The horizontal alignment. Possible values are 'left', 'center' or 'right'. |
'left'
|
title_size |
float
|
The title font size (in pt). |
16
|
subtitle_size |
float
|
The subtitle font size (in pt). |
13
|
v_space |
float
|
Vertical space between title and subtitle (in pt). |
2
|
h_offset |
float
|
Horizontal offset (in pt). A positive (negative) value specifies the amount of horizontal displacement towards the right (left) of the figure. The reference (zero) is the text anchor point as specified by 'aligment'. |
2
|
v_offset |
float
|
Vertical offset (in pt). A positive value specifies the amount of vertical displacement towards the bottom of the figure starting from the top border. A negative value has no effect. |
2
|
Returns:
Type | Description |
---|---|
None. |
Examples:
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots(figsize=(5,6))
>>> set_title_and_subtitle(fig=fig, title='Figure title',
... subtitle='Figure subtitle')
>>> fig.savefig(fname='title1.png')
Source code in mpl_ornaments\titles.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|