Created
January 17, 2013 02:54
-
-
Save tacaswell/4553135 to your computer and use it in GitHub Desktop.
Format nicely printed labels based on pi for matplotlib x-axis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def format_frac(fr): | |
'''Convert a/b to latex''' | |
sp = str(fr).split('/') | |
if len(sp) == 1: | |
return sp[0] | |
else: | |
return r'$\frac{%s}{%s}$' % tuple(sp) | |
frac_size = 4 | |
step = fractions.Fraction(1, frac_size) | |
ax.set_xticks([np.pi * j * step for j in range(2 * frac_size + 1)]) | |
ax.set_xticklabels([format_frac(j * step) + '$\pi$' for j in range(2 * frac_size + 1)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment