mpl.text.FontProperties¶
-
class
mpl.text.FontProperties(family=None, style=None, variant=None, weight=None, stretch=None, size=None, fname=None, _init=None)[source]¶ A class for storing and manipulating font properties.
The font properties are those described in the W3C Cascading Style Sheet, Level 1 font specification. The six properties are:
- family: A list of font names in decreasing order of priority.
The items may include a generic font family name, either
‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, or ‘monospace’.
In that case, the actual font to be used will be looked up
from the associated rcParam in
matplotlibrc. - style: Either ‘normal’, ‘italic’ or ‘oblique’.
- variant: Either ‘normal’ or ‘small-caps’.
- stretch: A numeric value in the range 0-1000 or one of ‘ultra-condensed’, ‘extra-condensed’, ‘condensed’, ‘semi-condensed’, ‘normal’, ‘semi-expanded’, ‘expanded’, ‘extra-expanded’ or ‘ultra-expanded’
- weight: A numeric value in the range 0-1000 or one of ‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’
- size: Either an relative value of ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’ or an absolute font size, e.g., 12
The default font property for TrueType fonts (as specified in the default
matplotlibrcfile) is:sans-serif, normal, normal, normal, normal, scalable.
Alternatively, a font may be specified using an absolute path to a .ttf file, by using the fname kwarg.
The preferred usage of font sizes is to use the relative values, e.g., ‘large’, instead of absolute font sizes, e.g., 12. This approach allows all text sizes to be made larger or smaller based on the font manager’s default font size.
This class will also accept a fontconfig pattern, if it is the only argument provided. See the documentation on fontconfig patterns. This support does not require fontconfig to be installed. We are merely borrowing its pattern syntax for use here.
Note that matplotlib’s internal font manager and fontconfig use a different algorithm to lookup fonts, so the results of the same pattern may be different in matplotlib than in other applications that use fontconfig.
- family: A list of font names in decreasing order of priority.
The items may include a generic font family name, either
‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, or ‘monospace’.
In that case, the actual font to be used will be looked up
from the associated rcParam in
Methods¶
__init__([family, style, variant, weight, ...]) |
|
copy() |
Return a deep copy of self |
get_family() |
Return a list of font names that comprise the font family. |
get_file() |
Return the filename of the associated font. |
get_fontconfig_pattern() |
Get a fontconfig pattern suitable for looking up the font as specified with fontconfig’s fc-match utility. |
get_name() |
Return the name of the font that best matches the font properties. |
get_size() |
Return the font size. |
get_size_in_points() |
|
get_slant() |
Return the font style. |
get_stretch() |
Return the font stretch or width. |
get_style() |
Return the font style. |
get_variant() |
Return the font variant. |
get_weight() |
Set the font weight. |
set_family(family) |
Change the font family. |
set_file(file) |
Set the filename of the fontfile to use. |
set_fontconfig_pattern(pattern) |
Set the properties by parsing a fontconfig pattern. |
set_name(family) |
Change the font family. |
set_size(size) |
Set the font size. |
set_slant(style) |
Set the font style. |
set_stretch(stretch) |
Set the font stretch or width. |
set_style(style) |
Set the font style. |
set_variant(variant) |
Set the font variant. |
set_weight(weight) |
Set the font weight. |