11"""
2- ==============
3- Custom Ticker1
4- ==============
2+ =============
3+ Custom Ticker
4+ =============
55
6- The new ticker code was designed to explicitly support user customized
7- ticking. The documentation of :mod:`matplotlib.ticker` details this
8- process. That code defines a lot of preset tickers but was primarily
9- designed to be user extensible.
6+ The :mod:`matplotlib.ticker` module defines many preset tickers, but was
7+ primarily designed for extensibility, i.e., to support user customized ticking.
108
11- In this example a user defined function is used to format the ticks in
9+ In this example, a user defined function is used to format the ticks in
1210millions of dollars on the y axis.
1311"""
14- import matplotlib .pyplot as plt
1512
16- money = [ 1.5e5 , 2.5e6 , 5.5e6 , 2.0e7 ]
13+ import matplotlib . pyplot as plt
1714
1815
1916def millions (x , pos ):
2017 """The two arguments are the value and tick position."""
2118 return '${:1.1f}M' .format (x * 1e-6 )
2219
20+
2321fig , ax = plt .subplots ()
24- # Use automatic FuncFormatter creation
22+ # set_major_formatter internally creates a FuncFormatter from the callable.
2523ax .yaxis .set_major_formatter (millions )
24+ money = [1.5e5 , 2.5e6 , 5.5e6 , 2.0e7 ]
2625ax .bar (['Bill' , 'Fred' , 'Mary' , 'Sue' ], money )
2726plt .show ()
2827
@@ -33,6 +32,4 @@ def millions(x, pos):
3332# The use of the following functions, methods, classes and modules is shown
3433# in this example:
3534#
36- # - `matplotlib.pyplot.subplots`
3735# - `matplotlib.axis.Axis.set_major_formatter`
38- # - `matplotlib.ticker.FuncFormatter`
0 commit comments