Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

font properties #149

Open
ljing1209 opened this issue Aug 26, 2023 · 1 comment
Open

font properties #149

ljing1209 opened this issue Aug 26, 2023 · 1 comment

Comments

@ljing1209
Copy link

Thanks for sharing!

I have a question about how to change the font for the label; I tried

font_path = fm.findfont(fm.FontProperties(family='Times New Roman'))
font_prop = fm.FontProperties(fname=font_path, size=18)

labelLines(axs["D"].get_lines(), align=True, fontsize=18,fontproperties=font_prop)

It seems can't work...

@gepcel
Copy link

gepcel commented Aug 30, 2023

Actually, you can use font and fontsize directly. For example:

import numpy as np
from matplotlib import pyplot as plt
from labellines import labelLines

x = np.linspace(0, 10, 300)

fig, ax = plt.subplots()
ax.plot(x, np.sin(x), label='np.sin')
labelLines(ax.get_lines(), zorder=2.5, font="Times New Roman", fontsize=18)

If you want to use fontproperties for some reason, you can try:

import  matplotlib.font_manager as fm
x = np.linspace(0, 10, 300)
font_prop = fm.FontProperties(family="Times New Roman", size=18)
fig, ax = plt.subplots()
ax.plot(x, np.sin(x), label='np.sin')
labelLines(ax.get_lines(), zorder=2.5, fontproperties=font_prop)

But in the end, your example of using the font_path should work. For example:

font_path = fm.findfont(fm.FontProperties(family='Times New Roman'))
font_prop = fm.FontProperties(fname=font_path, size=18)
fig, ax = plt.subplots()
ax.plot(x, np.sin(x), label='np.sin')
labelLines(ax.get_lines(), zorder=2.5, fontproperties=font_prop)

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

No branches or pull requests

2 participants