5

Until now I have this:

plt.xlabel('$\delta^1^8$O \‰ vs VSMOW') 

It runs fine without the promille sign, however when I add it a blank graph appears.

Then I tried TheImportanceOfBeingErnest's answer:

plt.xlabel(u'$\delta^{18}$O ‰ vs VSMOW') 

But then this showed up:

"UnicodeEncodeError: 'ascii' codec can't encode character '\u2030' in position 264: ordinal not in range(128)"

Maybe there is something wrong with this?

from matplotlib import rc

rc('font', **{'family':'serif','serif':['Palatino']})
    rc('text', usetex=True)

Solution (thanks to TheImportanceOfBeingErnest)

plt.rcParams['text.latex.preamble']=[r"\usepackage{wasysym}"]

and

plt.xlabel(r'$\delta^{18}$O \textperthousand vs VSMOW')

1 Answers1

8

Using normal text

You need to

  1. use a unicode string, i.e. u"string"
  2. not escape the character, i.e. exists, but \‰ does not.

So

plt.xlabel(u'$\delta^{18}$O ‰ vs VSMOW') 

produces

enter image description here

Using latex

Latex does not have a permille sign built in. Two ways to go would be

  • In text mode: use the \usepackage{textcomp} package and get it via \textperthousand,

    plt.xlabel(r'$\delta^{18}$O \textperthousand vs VSMOW') 
    
  • In math mode: use the package \usepackage{wasysym} and get it via \permil.

    plt.xlabel(r'$\delta^{18}$O $\permil$ vs VSMOW') 
    

    Using the first package and using \text{\textperthousand} inside math mode should work as well.

enter image description here

For how to get those packages into matplotlib, read How to write your own LaTeX preamble in Matplotlib?

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712