同一个 Matplotlib 标签中的多种字体大小 [英] Multiple font sizes in same Matplotlib label

查看:67
本文介绍了同一个 Matplotlib 标签中的多种字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一些相对简单的事情:

I'm trying to do something relatively simple:

我希望能够增加一个字母的字体(比如 LaTeX 变量,比如 30),并将标签中的其他字母保留为某种字体(比如 20).

I want to be able to increase a font of one letter(say a LaTeX variable, say to 30) and keep the other letters in the label a certain font(say 20).

有没有人有快速的解决方案?对我来说似乎相当复杂.我尝试对每个项目"使用 {} 在标签中

Does anyone have a quick solution? It seems rather complicated to me. I tried using { } for each "item" in the label

plt.plot(a,b,'g',linewidth=3.5, label = 'a')
plt.plot(c,d,'r',linewidth=3.5, label = 'c')

plt.legend(labelspacing = 1.0,loc=1,prop={'size':40})

plt.xlabel({'a',fontsize=50},{ 'N',fontsize = 20})
plt.ylabel('%',fontsize =30)

推荐答案

一种解决方案是使用text()并进行多个调用,并仔细选择每个字母的位置:

One solution is to use text() and make multiple calls, carefully selecting where each letter goes:

import pylab as plt
a=[0,1]
b=[0,1]
plt.plot(a,b,'g',linewidth=3.5, label = 'a')
plt.rc('text', usetex=True)
plt.legend(labelspacing = 1.0,loc=1,prop={'size':40})

plt.text(0.45,-0.08,'a',fontsize=50)
plt.text(0.53,-0.08, 'N',fontsize = 20)

这并不理想.另一种选择是通过 LaTeX.查看我即将发布的其他答案.

This isn't ideal. Another option is to go through LaTeX. See other answer I'm about to post.

这篇关于同一个 Matplotlib 标签中的多种字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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