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

set_xticklabels changes font when text.usetex is enabled #1516

Closed
rephorm opened this issue Nov 17, 2012 · 1 comment
Closed

set_xticklabels changes font when text.usetex is enabled #1516

rephorm opened this issue Nov 17, 2012 · 1 comment

Comments

@rephorm
Copy link

rephorm commented Nov 17, 2012

If text.usetex is enabled, then setting tick labels using Axes.set_xticklabels causes the font to be changed (as if text.usetex were disabled) for that axis.

import numpy as np
from matplotlib import pyplot as pt, rcParams

rcParams['text.usetex'] = True

x = np.linspace(0,10,101)
y = np.sin(x)

fig = pt.figure(figsize=(3.375, 2.5))
ax = fig.add_axes([.15,.15,.8,.8])

pt.plot(x, y)
pt.xlabel(r'$\alpha$')
pt.savefig('mpl_font_testA.png')

ax.set_xticklabels(np.arange(0,11,2))
pt.savefig('mpl_font_testB.png')

Example output is below.

Before calling ax.set_xticklabels:
mpl_font_testA.png

After calling ax.set_xticklabels:
mpl_font_testB.png

@rephorm
Copy link
Author

rephorm commented Nov 17, 2012

After reading through the code for ScalarFormatter, it looks like the solution is to include "$" delimiters around the labels, e.g.:

ax.set_xticklabels(["$%d$"%f for f in np.arange(0,11,2)])

@rephorm rephorm closed this as completed Nov 17, 2012
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

1 participant