|
1 | 1 | """ |
2 | | -========================================= |
3 | | -Tick formatting using the ScalarFormatter |
4 | | -========================================= |
| 2 | +========================== |
| 3 | +The default tick formatter |
| 4 | +========================== |
5 | 5 |
|
6 | | -The example shows use of ScalarFormatter with different settings. |
| 6 | +The example shows use of the default `ScalarFormatter` with different settings. |
7 | 7 |
|
8 | 8 | Example 1 : Default |
9 | 9 |
|
10 | 10 | Example 2 : With no Numerical Offset |
11 | 11 |
|
12 | 12 | Example 3 : With Mathtext |
13 | 13 | """ |
| 14 | + |
14 | 15 | import matplotlib.pyplot as plt |
15 | 16 | import numpy as np |
16 | | -from matplotlib.ticker import ScalarFormatter |
17 | 17 |
|
18 | 18 | ############################################################################### |
19 | 19 | # Example 1 |
20 | 20 |
|
21 | 21 | x = np.arange(0, 1, .01) |
22 | 22 | fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6)) |
23 | | -fig.text(0.5, 0.975, 'The new formatter, default settings', |
| 23 | +fig.text(0.5, 0.975, 'Default settings', |
24 | 24 | horizontalalignment='center', |
25 | 25 | verticalalignment='top') |
26 | 26 |
|
27 | 27 | ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) |
28 | | -ax1.xaxis.set_major_formatter(ScalarFormatter()) |
29 | | -ax1.yaxis.set_major_formatter(ScalarFormatter()) |
30 | 28 |
|
31 | 29 | ax2.plot(x * 1e5, x * 1e-4) |
32 | | -ax2.xaxis.set_major_formatter(ScalarFormatter()) |
33 | | -ax2.yaxis.set_major_formatter(ScalarFormatter()) |
34 | 30 |
|
35 | 31 | ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) |
36 | | -ax3.xaxis.set_major_formatter(ScalarFormatter()) |
37 | | -ax3.yaxis.set_major_formatter(ScalarFormatter()) |
38 | 32 |
|
39 | 33 | ax4.plot(-x * 1e5, -x * 1e-4) |
40 | | -ax4.xaxis.set_major_formatter(ScalarFormatter()) |
41 | | -ax4.yaxis.set_major_formatter(ScalarFormatter()) |
42 | 34 |
|
43 | 35 | fig.subplots_adjust(wspace=0.7, hspace=0.6) |
44 | 36 |
|
|
47 | 39 |
|
48 | 40 | x = np.arange(0, 1, .01) |
49 | 41 | fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6)) |
50 | | -fig.text(0.5, 0.975, 'The new formatter, no numerical offset', |
| 42 | +fig.text(0.5, 0.975, 'No numerical offset', |
51 | 43 | horizontalalignment='center', |
52 | 44 | verticalalignment='top') |
53 | 45 |
|
54 | 46 | ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) |
55 | | -ax1.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
56 | | -ax1.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
| 47 | +ax1.ticklabel_format(useOffset=False) |
57 | 48 |
|
58 | 49 | ax2.plot(x * 1e5, x * 1e-4) |
59 | | -ax2.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
60 | | -ax2.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
| 50 | +ax2.ticklabel_format(useOffset=False) |
61 | 51 |
|
62 | 52 | ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) |
63 | | -ax3.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
64 | | -ax3.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
| 53 | +ax3.ticklabel_format(useOffset=False) |
65 | 54 |
|
66 | 55 | ax4.plot(-x * 1e5, -x * 1e-4) |
67 | | -ax4.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
68 | | -ax4.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
| 56 | +ax4.ticklabel_format(useOffset=False) |
69 | 57 |
|
70 | 58 | fig.subplots_adjust(wspace=0.7, hspace=0.6) |
71 | 59 |
|
|
74 | 62 |
|
75 | 63 | x = np.arange(0, 1, .01) |
76 | 64 | fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6)) |
77 | | -fig.text(0.5, 0.975, 'The new formatter, with mathtext', |
| 65 | +fig.text(0.5, 0.975, 'With mathtext', |
78 | 66 | horizontalalignment='center', |
79 | 67 | verticalalignment='top') |
80 | 68 |
|
81 | 69 | ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) |
82 | | -ax1.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
83 | | -ax1.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
| 70 | +ax1.ticklabel_format(useMathText=True) |
84 | 71 |
|
85 | 72 | ax2.plot(x * 1e5, x * 1e-4) |
86 | | -ax2.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
87 | | -ax2.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
| 73 | +ax2.ticklabel_format(useMathText=True) |
88 | 74 |
|
89 | 75 | ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) |
90 | | -ax3.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
91 | | -ax3.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
| 76 | +ax3.ticklabel_format(useMathText=True) |
92 | 77 |
|
93 | 78 | ax4.plot(-x * 1e5, -x * 1e-4) |
94 | | -ax4.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
95 | | -ax4.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
| 79 | +ax4.ticklabel_format(useMathText=True) |
96 | 80 |
|
97 | 81 | fig.subplots_adjust(wspace=0.7, hspace=0.6) |
98 | 82 |
|
|
0 commit comments