matplotlib-label-lines
matplotlib-label-lines copied to clipboard
font properties
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...
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)