Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Won't write \approx LaTeX character in legend? #3254

Closed
Gabriel-p opened this issue Jul 14, 2014 · 4 comments
Closed

Won't write \approx LaTeX character in legend? #3254

Gabriel-p opened this issue Jul 14, 2014 · 4 comments

Comments

@Gabriel-p
Copy link

For some reason I can't get matplotlib to write down the \approx LaTeX symbol in a legend.

Here's a MWE:

import matplotlib.pyplot as plt
plt.scatter([0.5, 0.5], [0.5, 0.5], label='$U_{c} \approx %0.1f$' % 22)
#plt.scatter([0.5, 0.5], [0.5, 0.5], label='$U_{c} \simeq %0.1f$' % 22)
#plt.scatter([0.5, 0.5], [0.5, 0.5], label='$U_{c} \sim %0.1f$' % 22)
plt.legend(fancybox=True, loc='upper right', scatterpoints=1, fontsize=16)
plt.show()

Notice the first line will not show the \approx character or the value after it but both \simeq and \sim work fine.

@Gabriel-p Gabriel-p changed the title Won't write \approx LaTeX char? Won't write \approx LaTeX character in legend? Jul 14, 2014
@Gabriel-p
Copy link
Author

Nevermind, forgot the r char.

http://stackoverflow.com/a/24739481/1391441

@mdboom
Copy link
Member

mdboom commented Jul 14, 2014

It's always recommended to use raw strings when specifying LaTeX, since otherwise the \a in \approx gets converted to a "bell" character.

Stick r in front of the string or double-escape the slash:

r'$U_{c} \approx %0.1f$'
'$U_{c} \\approx %0.1f$'

@mdboom
Copy link
Member

mdboom commented Jul 14, 2014

I think I sent my comment the same moment you sent yours ;)

@Gabriel-p
Copy link
Author

@mdboom you did but thank you very much nonetheless :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants