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

annotate font setting is ineffective #902

Open
mengyuhs opened this issue Dec 9, 2024 · 1 comment
Open

annotate font setting is ineffective #902

mengyuhs opened this issue Dec 9, 2024 · 1 comment
Labels

Comments

@mengyuhs
Copy link

mengyuhs commented Dec 9, 2024

设置中文字体

font_path = 'app/fonts/字体文件-宋体_常规.ttc'
font_prop = FontProperties(fname=font_path)
my_font = font_prop.get_name()
plt.rcParams['font.family'] = my_font
plt.rcParams['font.sans-serif'] = my_font
plt.rcParams['axes.unicode_minus'] = False

     annotate("text", x=school_clazz_size + 0.2, y=school_mean_score,
              nudge_x=0.2, nudge_y=0,
              label=f"本校平均\n{school_mean_score}%",
              size=10, color='black', family=my_font) 

findfont: Font family 'SimSun' not found.

@has2k1
Copy link
Owner

has2k1 commented Dec 10, 2024

Add fonts like this.

from matplotlib import font_manager as fm

font_file = "app/fonts/字体文件-宋体_常规.ttc"
fm.fontManager.addfont(font_file)

Then you can use it as family="font-name"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
@has2k1 @mengyuhs and others