Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0ee82be commit 0c22d3bCopy full SHA for 0c22d3b
1 file changed
examples/pylab_examples/histogram_percent_demo.py
@@ -0,0 +1,22 @@
1
+from numpy.random import randn
2
+import matplotlib.pyplot as plt
3
+from matplotlib.ticker import FuncFormatter
4
+
5
+def to_percent(y, position):
6
+ # Ignore the passed in position. This has the effect of scaling the default
7
+ # tick locations.
8
+ return str(100 * y)
9
10
+x = randn(5000)
11
12
+# Make a normed histogram. It'll be multiplied by 100 later.
13
+plt.hist(x, bins=50, normed=True)
14
15
+# Create the formatter using the function to_percent. This multiplies all the
16
+# default labels by 100, making them all percentages
17
+formatter = FuncFormatter(to_percent)
18
19
+# Set the formatter
20
+plt.gca().yaxis.set_major_formatter(formatter)
21
22
+plt.show()
0 commit comments