11

I'm trying to do something relatively simple:

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)
john-hen
  • 4,410
  • 2
  • 23
  • 40
John M
  • 273
  • 2
  • 11

2 Answers2

8

Here is the solution with LaTeX. The machine I have doesn't have LaTeX installed, so I haven't tested this carefully.

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.xlabel(r'{\fontsize{50pt}{3em}\selectfont{}a}{\fontsize{20pt}{3em}\selectfont{}N')

(note the r before the string. This tells pylab to just send the string directly to LaTeX as a raw string rather than treating \f and \s as special characters)

You can get much more elaborate with the size commands of LaTeX (you can specify the actual font, or use various versions of the \large, \Large, \small \tiny ... commands).

Joel
  • 22,598
  • 6
  • 69
  • 93
  • This solution isn't as strong as the first one you provided since you can't control the size of \large{} and \small{} as effectively as fontsize. rc still has TeX support too. Thanks – John M Jan 08 '15 at 20:53
  • 1
    I believe that the edit I just did will exactly set the font sizes. I'm not able to test since LaTeX doesn't run on the laptop I have here. – Joel Jan 08 '15 at 21:11
  • Yeah that doesn't work on my ipython notebook, but I suspect my TexLive is bugged a bit so its hard to tell. Anyone else check this? – John M Jan 08 '15 at 21:22
1

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)

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

Joel
  • 22,598
  • 6
  • 69
  • 93