diff --git a/examples/ticks/custom_ticker1.py b/examples/ticks/custom_ticker1.py index ee088fa4d5af..f3e0ec4ef3bf 100644 --- a/examples/ticks/custom_ticker1.py +++ b/examples/ticks/custom_ticker1.py @@ -1,28 +1,27 @@ """ -============== -Custom Ticker1 -============== +============= +Custom Ticker +============= -The new ticker code was designed to explicitly support user customized -ticking. The documentation of :mod:`matplotlib.ticker` details this -process. That code defines a lot of preset tickers but was primarily -designed to be user extensible. +The :mod:`matplotlib.ticker` module defines many preset tickers, but was +primarily designed for extensibility, i.e., to support user customized ticking. -In this example a user defined function is used to format the ticks in +In this example, a user defined function is used to format the ticks in millions of dollars on the y axis. """ -import matplotlib.pyplot as plt -money = [1.5e5, 2.5e6, 5.5e6, 2.0e7] +import matplotlib.pyplot as plt def millions(x, pos): """The two arguments are the value and tick position.""" return '${:1.1f}M'.format(x*1e-6) + fig, ax = plt.subplots() -# Use automatic FuncFormatter creation +# set_major_formatter internally creates a FuncFormatter from the callable. ax.yaxis.set_major_formatter(millions) +money = [1.5e5, 2.5e6, 5.5e6, 2.0e7] ax.bar(['Bill', 'Fred', 'Mary', 'Sue'], money) plt.show() @@ -33,6 +32,4 @@ def millions(x, pos): # The use of the following functions, methods, classes and modules is shown # in this example: # -# - `matplotlib.pyplot.subplots` # - `matplotlib.axis.Axis.set_major_formatter` -# - `matplotlib.ticker.FuncFormatter`