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

Skip to content

Commit 8be01cc

Browse files
authored
Merge pull request #13815 from timhoffm/doc-findfont
Numpydocify FontManager.findfont()
2 parents 4eb452a + 5399fec commit 8be01cc

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

lib/matplotlib/font_manager.py

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,28 +1177,53 @@ def score_size(self, size1, size2):
11771177
def findfont(self, prop, fontext='ttf', directory=None,
11781178
fallback_to_default=True, rebuild_if_missing=True):
11791179
"""
1180-
Search the font list for the font that most closely matches
1181-
the :class:`FontProperties` *prop*.
1182-
1183-
:meth:`findfont` performs a nearest neighbor search. Each
1184-
font is given a similarity score to the target font
1185-
properties. The first font with the highest score is
1186-
returned. If no matches below a certain threshold are found,
1187-
the default font (usually DejaVu Sans) is returned.
1188-
1189-
`directory`, is specified, will only return fonts from the
1190-
given directory (or subdirectory of that directory).
1180+
Find a font that most closely matches the given font properties.
1181+
1182+
Parameters
1183+
----------
1184+
prop : str or `~matplotlib.font_manager.FontProperties`
1185+
The font properties to search for. This can be either a
1186+
`.FontProperties` object or a string defining a
1187+
`fontconfig patterns`_.
1188+
1189+
fontext : {'ttf', 'afm'}, optional, default: 'ttf'
1190+
The extension of the font file:
1191+
1192+
- 'ttf': TrueType and OpenType fonts (.ttf, .ttc, .otf)
1193+
- 'afm': Adobe Font Metrics (.afm)
1194+
1195+
directory : str, optional
1196+
If given, only search this directory and its subdirectories.
1197+
fallback_to_default : bool
1198+
If True, will fallback to the default font family (usually
1199+
"DejaVu Sans" or "Helvetica") if the first lookup hard-fails.
1200+
rebuild_if_missing : bool
1201+
Whether to rebuild the font cache and search again if no match
1202+
is found.
1203+
1204+
Returns
1205+
-------
1206+
fontfile : str
1207+
The filename of the best matching font.
1208+
1209+
Notes
1210+
-----
1211+
This performs a nearest neighbor search. Each font is given a
1212+
similarity score to the target font properties. The first font with
1213+
the highest score is returned. If no matches below a certain
1214+
threshold are found, the default font (usually DejaVu Sans) is
1215+
returned.
11911216
11921217
The result is cached, so subsequent lookups don't have to
11931218
perform the O(n) nearest neighbor search.
11941219
1195-
If `fallback_to_default` is True, will fallback to the default
1196-
font family (usually "DejaVu Sans" or "Helvetica") if
1197-
the first lookup hard-fails.
1198-
11991220
See the `W3C Cascading Style Sheet, Level 1
12001221
<http://www.w3.org/TR/1998/REC-CSS2-19980512/>`_ documentation
12011222
for a description of the font finding algorithm.
1223+
1224+
.. _fontconfig patterns:
1225+
https://www.freedesktop.org/software/fontconfig/fontconfig-user.html
1226+
12021227
"""
12031228
# Pass the relevant rcParams (and the font manager, as `self`) to
12041229
# _findfont_cached so to prevent using a stale cache entry after an

0 commit comments

Comments
 (0)