在matplotlib中更改刻度标签的字体 [英] Change font of tick labels in matplotlib
本文介绍了在matplotlib中更改刻度标签的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改 matplotlib 刻度标签的字体?我想将其更改为 Computer Modern 10(我相信在 matplotlib 中称为cm"),但是,我不想在 TeX 中渲染它.我尝试了许多方法来执行此操作,但似乎都没有用.
How can I change the font of matplotlib tick labels? I'd like to change it to Computer Modern 10 (called "cm" in matplotlib I believe), however, I don't want to render it in TeX. I've tried numerous ways of doing this, but none of them seem to work.
推荐答案
func = lambda x, pos: "" if np.isclose(x,0) else x
plt.gca().xaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(func))
plt.gca().yaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(func))
在我的情况下有效!
这篇关于在matplotlib中更改刻度标签的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文