|
3 | 3 | # Author: Nicolas P. Rougier
|
4 | 4 | # License: BSD
|
5 | 5 | # ----------------------------------------------------------------------------
|
6 |
| -import numpy as np |
7 | 6 | import matplotlib.pyplot as plt
|
8 | 7 | import matplotlib.ticker as ticker
|
9 | 8 |
|
10 | 9 | # Setup a plot such that only the bottom spine is shown
|
11 | 10 |
|
12 | 11 |
|
13 | 12 | def setup(ax):
|
| 13 | + """Set up Axes with just an x-Axis.""" |
14 | 14 | ax.spines['right'].set_color('none')
|
15 | 15 | ax.spines['left'].set_color('none')
|
16 | 16 | ax.yaxis.set_major_locator(ticker.NullLocator())
|
@@ -43,20 +43,18 @@ def setup(ax):
|
43 | 43 | # Fixed formatter
|
44 | 44 | ax = fig.add_subplot(n, 1, 2)
|
45 | 45 | setup(ax)
|
46 |
| -ax.xaxis.set_major_locator(ticker.MultipleLocator(1.0)) |
47 | 46 | ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25))
|
48 |
| -majors = ["", "0", "1", "2", "3", "4", "5"] |
| 47 | +ax.xaxis.set_major_locator(ticker.FixedLocator(range(6))) |
| 48 | +majors = ["zero", "one", "two", "three", "four", "five"] |
49 | 49 | ax.xaxis.set_major_formatter(ticker.FixedFormatter(majors))
|
50 |
| -minors = [""] + ["%.2f" % (x-int(x)) if (x-int(x)) |
51 |
| - else "" for x in np.arange(0, 5, 0.25)] |
52 |
| -ax.xaxis.set_minor_formatter(ticker.FixedFormatter(minors)) |
53 |
| -ax.text(0.0, 0.1, "ticker.FixedFormatter(['', '0', '1', ...])", |
| 50 | +ax.text(0.0, 0.1, "ticker.FixedFormatter(['zero', 'one', 'two', …])", |
54 | 51 | family=family, fontsize=fontsize, transform=ax.transAxes)
|
55 | 52 |
|
56 | 53 |
|
57 | 54 | # FuncFormatter can be used as a decorator
|
58 | 55 | @ticker.FuncFormatter
|
59 | 56 | def major_formatter(x, pos):
|
| 57 | + """Return formatted value with 2 decimal places.""" |
60 | 58 | return "[%.2f]" % x
|
61 | 59 |
|
62 | 60 |
|
|
0 commit comments