Skip to content

[Doc]: add from file to font family example #24419

@story645

Description

@story645

Documentation Link

https://matplotlib.org/devdocs/gallery/text_labels_and_annotations/font_family_rc.html

Problem

The only documentation I could find of adding a font from file was using a ttf file which is about pointing to a specific file in text. We have the FontManager API but addfont is not used in any examples & we don't really document that to add a new font family you have to add all the .ttf/.afm files with that font, indivdually.

Suggested improvement

Amend the font family example to add a font family from file example. I don't guarantee this could works but it should be something like

Edit: working example from @mikan3rd #17568 (comment)

from matplotlib import font_manager

font_dirs = ["/resources/fonts"]
font_files = font_manager.findSystemFonts(fontpaths=font_dirs)

for font_file in font_files:
    font_manager.fontManager.addfont(font_file)

and then use one of the font names of the new fonts in ax.text(x,y, s, font=name)to show how it works. Including maybe changing weights and the like to show the different family properties.

I think it's a good first issue because it's fairly self contained. I suggest using the font folder in source lib/matolotlib/mpl-data/fonts for the example cause that one should build.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions