如何更改matplotlib(python)中的字体? [英] How to change fonts in matplotlib (python)?

查看:468
本文介绍了如何更改matplotlib(python)中的字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这听起来像一个简单的问题,但我没有找到任何有效的解决方案来改变在python matplotlib作出的阴谋字体(而不是字体大小)。

我发现了一些教程,通过修改matplotlib存储其默认字体的文件夹中的某些文件来更改matplotlib的默认字体 - 请参阅

和$ Helvetica为x标签。

pre code $ csfont = {'fontname':'Comic Sans MS'}
hfont = {'fontname':'Helvetica'}

plt.title('title',** csfont)
plt.xlabel('xlabel',** hfont)
plt .show()


It sounds as an easy problem but I do not find any effective solution to change the font (not the font size) in a plot made with matplotlib in python.

I found a couple of tutorials to change the default font of matplotlib by modifying some files in the folders where matplotlib stores its default font - see this blog post - but I am looking for a less radical solution since I would like to use more than one font in my plot (text, label, axis label, etc).

解决方案

Say you want Comic Sans for the title and Helvetica for the x label.

csfont = {'fontname':'Comic Sans MS'}
hfont = {'fontname':'Helvetica'}

plt.title('title',**csfont)
plt.xlabel('xlabel', **hfont)
plt.show()

这篇关于如何更改matplotlib(python)中的字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆