1
1
"""
2
- ==============
3
- Custom Ticker1
4
- ==============
2
+ =============
3
+ Custom Ticker
4
+ =============
5
5
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.
10
8
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
12
10
millions of dollars on the y axis.
13
11
"""
14
- import matplotlib .pyplot as plt
15
12
16
- money = [ 1.5e5 , 2.5e6 , 5.5e6 , 2.0e7 ]
13
+ import matplotlib . pyplot as plt
17
14
18
15
19
16
def millions (x , pos ):
20
17
"""The two arguments are the value and tick position."""
21
18
return '${:1.1f}M' .format (x * 1e-6 )
22
19
20
+
23
21
fig , ax = plt .subplots ()
24
- # Use automatic FuncFormatter creation
22
+ # set_major_formatter internally creates a FuncFormatter from the callable.
25
23
ax .yaxis .set_major_formatter (millions )
24
+ money = [1.5e5 , 2.5e6 , 5.5e6 , 2.0e7 ]
26
25
ax .bar (['Bill' , 'Fred' , 'Mary' , 'Sue' ], money )
27
26
plt .show ()
28
27
@@ -33,6 +32,4 @@ def millions(x, pos):
33
32
# The use of the following functions, methods, classes and modules is shown
34
33
# in this example:
35
34
#
36
- # - `matplotlib.pyplot.subplots`
37
35
# - `matplotlib.axis.Axis.set_major_formatter`
38
- # - `matplotlib.ticker.FuncFormatter`
0 commit comments