python中fontproperties_Python matplotlib 模块,font_manager() 实例源码 - 编程字典

越伯寅
2023-12-01

def set_font(self, font_dict=None):

"""

Set the font and font properties.

Parameters

----------

font_dict : dict

A dict of keyword parameters to be passed to

:class:`matplotlib.font_manager.FontProperties`.

Possible keys include:

* family - The font family. Can be serif, sans-serif, cursive,

'fantasy', or 'monospace'.

* style - The font style. Either normal, italic or oblique.

* color - A valid color string like 'r', 'g', 'red', 'cobalt',

and 'orange'.

* variant - Either normal or small-caps.

* size - Either a relative value of xx-small, x-small, small,

medium, large, x-large, xx-large or an absolute font size, e.g. 12

* 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, or black

See the matplotlib font manager API documentation for more details.

http://matplotlib.org/api/font_manager_api.html

Notes

-----

Mathtext axis labels will only obey the `size` and `color` keyword.

Examples

--------

This sets the font to be 24-pt, blue, sans-serif, italic, and

bold-face.

>>> prof = ProfilePlot(ds.all_data(), 'density', 'temperature')

>>> slc.set_font({'family':'sans-serif', 'style':'italic',

... 'weight':'bold', 'size':24, 'color':'blue'})

"""

from matplotlib.font_manager import FontProperties

if font_dict is None:

font_dict = {}

if 'color' in font_dict:

self._font_color = font_dict.pop('color')

# Set default values if the user does not explicitly set them.

# this prevents reverting to the matplotlib defaults.

font_dict.setdefault('family', 'stixgeneral')

font_dict.setdefault('size', 18)

self._font_properties = \

FontProperties(**font_dict)

return self

 类似资料: