Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Add Phil Elson's percentage histogram example #1149

merged 2 commits into from

3 participants


Addresses issue #320. The example is @pelson's, I just added some comments. Also, Gaussians look pretty.


Seems fine. Did you look into the potential of using a scale? I've never done it that way, but it seems that (in my head at least) that would be a viable solution too.

I'm happy enough with this approach though. +1


I did not. I thought yours was good enough! :)


It might be slightly better if the formatter added a percent symbol at the end, but otherwise, I think this is good to go.

Milestoning this to 1.2.x since #320 is also.

@dmcdougall dmcdougall Add a percent symbol to tick labels
Got to be careful when latex is involved.

So yeah, it's a bit more fiddly to use the percent symbol with latex.

@mdboom mdboom merged commit 47a61d7 into matplotlib:master
@mdboom mdboom referenced this pull request

hist plot in percent #320

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 27, 2012
  1. @dmcdougall
Commits on Aug 28, 2012
  1. @dmcdougall

    Add a percent symbol to tick labels

    dmcdougall authored
    Got to be careful when latex is involved.
This page is out of date. Refresh to see the latest.
Showing with 29 additions and 0 deletions.
  1. +29 −0 examples/pylab_examples/
29 examples/pylab_examples/
@@ -0,0 +1,29 @@
+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.
+ 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)
+# Make a normed histogram. It'll be multiplied by 100 later.
+plt.hist(x, bins=50, normed=True)
+# Create the formatter using the function to_percent. This multiplies all the
+# default labels by 100, making them all percentages
+formatter = FuncFormatter(to_percent)
+# Set the formatter
Something went wrong with that request. Please try again.