Permalink
Browse files

Add a percent symbol to tick labels

Got to be careful when latex is involved.
  • Loading branch information...
1 parent 0c22d3b commit 1985162ee89263aa069ee2b8153a780aeabca7d9 @dmcdougall committed Aug 28, 2012
Showing with 8 additions and 1 deletion.
  1. +8 −1 examples/pylab_examples/histogram_percent_demo.py
View
9 examples/pylab_examples/histogram_percent_demo.py
@@ -1,11 +1,18 @@
+import matplotlib
from numpy.random import randn
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
def to_percent(y, position):
# Ignore the passed in position. This has the effect of scaling the default
# tick locations.
- return str(100 * y)
+ s = str(100 * y)
+
+ # The percent symbol needs escaping in latex
+ if matplotlib.rcParams['text.usetex'] == True:
+ return s + r'$\%$'
+ else:
+ return s + '%'
x = randn(5000)

0 comments on commit 1985162

Please sign in to comment.