Skip to content

Add custom fonts directly to Matplotlib#129

Open
QuLogic wants to merge 1 commit into
matplotlib:mainfrom
QuLogic:custom-font
Open

Add custom fonts directly to Matplotlib#129
QuLogic wants to merge 1 commit into
matplotlib:mainfrom
QuLogic:custom-font

Conversation

@QuLogic

@QuLogic QuLogic commented Mar 29, 2023

Copy link
Copy Markdown
Member

This removes the need to manually install them system- or user-wide.

This depends on my other PRs, so will be in draft until they're merged.

This removes the need to manually install them system- or user-wide.
@QuLogic QuLogic marked this pull request as ready for review February 6, 2024 10:11
Comment thread scripts/adjustements.py


ROOT_DIR = pathlib.Path(__file__).parent.parent
sys.path.append(str(ROOT_DIR / "fonts"))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have to put the fonts directory on the path?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that it may be imported, regardless of where you run the script from.

@dstansby dstansby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in theory to me - needs a rebase, and I left a couple of comments.

Comment thread fonts/custom_fonts.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To convey that this file does something on import, could it be renamed to setup_fonts.py?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, put the code in a function and then in all the files below have something like

import custom_fonts
custom_fonts.setup_fonts()

It's a bit more verbose, but more obvious that code is being run to setup the fonts. I'm not too bothered either way, just a suggestion.

Comment thread fonts/custom_fonts.py

HERE = Path(__file__).parent.resolve()
for font in HERE.glob('*/*.[ot]tf'):
fontManager.addfont(font)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are being directly added to the font manager, does that mean the following part of the README no longer applies?

The fonts can be made discoverable by matplotlib (through fontconfig) by creating the following in $HOME/.config/fontconfig/fonts.conf (see here):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants