1

I have a custom .ttf file and I am trying to use it in a seaborn plot. Here's what I have so far:

from matplotlib import font_manager
path = "path/to/Roboto-Black.ttf"
fm = font_manager.FontManager()
fm.addfont(path)

prop = font_manager.FontProperties(fname=path)
sns.set(font=prop.get_name())

But this doesn't work, I simply get the warning:

findfont: Font family 'Roboto' not found.

I am using the latest matplotlib version 3.6.1. Also, I cannot install any fonts in the system as I don't have sudo access.

1 Answer 1

5

There is a default FontManager instance that needs to be used rather than creating a new instance:

from matplotlib.font_manager import fontManager, FontProperties

path = "path/to/Roboto-Black.ttf"
fontManager.addfont(path)

prop = FontProperties(fname=path)
sns.set(font=prop.get_name())

See source for more details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.