matplotlib 3.5.1

NotesParametersReturnsBackRef
findfont(self, prop, fontext='ttf', directory=None, fallback_to_default=True, rebuild_if_missing=True)

Notes

This performs a nearest neighbor search. Each font is given a similarity score to the target font properties. The first font with the highest score is returned. If no matches below a certain threshold are found, the default font (usually DejaVu Sans) is returned.

The result is cached, so subsequent lookups don't have to perform the O(n) nearest neighbor search.

See the :None:None:`W3C Cascading Style Sheet, Level 1 <http://www.w3.org/TR/1998/REC-CSS2-19980512/>` documentation for a description of the font finding algorithm.

            <Unimplemented 'target' '.. _fontconfig patterns:\n   https://www.freedesktop.org/software/fontconfig/fontconfig-user.html'>
           

Parameters

prop : str or `~matplotlib.font_manager.FontProperties`

The font properties to search for. This can be either a .FontProperties object or a string defining a :None:None:`fontconfig patterns`.

fontext : {'ttf', 'afm'}, default: 'ttf'

The extension of the font file:

  • 'ttf': TrueType and OpenType fonts (.ttf, .ttc, .otf)

  • 'afm': Adobe Font Metrics (.afm)

directory : str, optional

If given, only search this directory and its subdirectories.

fallback_to_default : bool

If True, will fallback to the default font family (usually "DejaVu Sans" or "Helvetica") if the first lookup hard-fails.

rebuild_if_missing : bool

Whether to rebuild the font cache and search again if the first match appears to point to a nonexisting font (i.e., the font cache contains outdated entries).

Returns

str

The filename of the best matching font.

Find a font that most closely matches the given font properties.

Examples

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

matplotlib.font_manager.FontManager matplotlib.font_manager

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /matplotlib/font_manager.py#1248
type: <class 'function'>
Commit: