|
1 |
| -# from pylab import * |
2 | 1 | import matplotlib.pyplot as plt
|
3 | 2 | import numpy as np
|
4 | 3 | from matplotlib.ticker import OldScalarFormatter, ScalarFormatter
|
5 | 4 |
|
| 5 | +## Example 1 ## |
6 | 6 | x = np.arange(0, 1, .01)
|
7 | 7 | f = plt.figure(figsize=(6, 6))
|
8 | 8 | f.text(0.5, 0.975, 'The old formatter',
|
9 | 9 | horizontalalignment='center', verticalalignment='top')
|
| 10 | + |
10 | 11 | plt.subplot(221)
|
11 | 12 | plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
|
12 |
| -plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) |
13 |
| -plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) |
| 13 | +ax1 = plt.gca() |
| 14 | +ax1.xaxis.set_major_formatter(OldScalarFormatter()) |
| 15 | +ax1.yaxis.set_major_formatter(OldScalarFormatter()) |
| 16 | + |
14 | 17 | plt.subplot(222)
|
15 | 18 | plt.plot(x * 1e5, x * 1e-4)
|
16 |
| -plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) |
17 |
| -plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) |
| 19 | +ax2 = plt.gca() |
| 20 | +ax2.xaxis.set_major_formatter(OldScalarFormatter()) |
| 21 | +ax2.yaxis.set_major_formatter(OldScalarFormatter()) |
| 22 | + |
18 | 23 | plt.subplot(223)
|
19 | 24 | plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
|
20 |
| -plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) |
21 |
| -plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) |
| 25 | +ax3 = plt.gca() |
| 26 | +ax3.xaxis.set_major_formatter(OldScalarFormatter()) |
| 27 | +ax3.yaxis.set_major_formatter(OldScalarFormatter()) |
| 28 | + |
22 | 29 | plt.subplot(224)
|
23 | 30 | plt.plot(-x * 1e5, -x * 1e-4)
|
24 |
| -plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) |
25 |
| -plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) |
| 31 | +ax4 = plt.gca() |
| 32 | +ax4.xaxis.set_major_formatter(OldScalarFormatter()) |
| 33 | +ax4.yaxis.set_major_formatter(OldScalarFormatter()) |
26 | 34 |
|
| 35 | +## Example 2 ## |
27 | 36 | x = np.arange(0, 1, .01)
|
28 |
| -f = figure(figsize=(6, 6)) |
| 37 | +f = plt.figure(figsize=(6, 6)) |
29 | 38 | f.text(0.5, 0.975, 'The new formatter, default settings',
|
30 | 39 | horizontalalignment='center',
|
31 | 40 | verticalalignment='top')
|
| 41 | + |
32 | 42 | plt.subplot(221)
|
33 | 43 | plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
|
34 |
| -plt.gca().xaxis.set_major_formatter(ScalarFormatter()) |
35 |
| -plt.gca().yaxis.set_major_formatter(ScalarFormatter()) |
| 44 | +ax1 = plt.gca() |
| 45 | +ax1.xaxis.set_major_formatter(ScalarFormatter()) |
| 46 | +ax1.yaxis.set_major_formatter(ScalarFormatter()) |
| 47 | + |
36 | 48 | plt.subplot(222)
|
37 | 49 | plt.plot(x * 1e5, x * 1e-4)
|
38 |
| -plt.gca().xaxis.set_major_formatter(ScalarFormatter()) |
39 |
| -plt.gca().yaxis.set_major_formatter(ScalarFormatter()) |
| 50 | +ax2 = plt.gca() |
| 51 | +ax2.xaxis.set_major_formatter(ScalarFormatter()) |
| 52 | +ax2.yaxis.set_major_formatter(ScalarFormatter()) |
| 53 | + |
40 | 54 | plt.subplot(223)
|
41 | 55 | plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
|
42 |
| -plt.gca().xaxis.set_major_formatter(ScalarFormatter()) |
43 |
| -plt.gca().yaxis.set_major_formatter(ScalarFormatter()) |
| 56 | +ax3 = plt.gca() |
| 57 | +ax3.xaxis.set_major_formatter(ScalarFormatter()) |
| 58 | +ax3.yaxis.set_major_formatter(ScalarFormatter()) |
| 59 | + |
44 | 60 | plt.subplot(224)
|
45 | 61 | plt.plot(-x * 1e5, -x * 1e-4)
|
46 |
| -plt.gca().xaxis.set_major_formatter(ScalarFormatter()) |
47 |
| -plt.gca().yaxis.set_major_formatter(ScalarFormatter()) |
| 62 | +ax4 = plt.gca() |
| 63 | +ax4.xaxis.set_major_formatter(ScalarFormatter()) |
| 64 | +ax4.yaxis.set_major_formatter(ScalarFormatter()) |
48 | 65 |
|
| 66 | +## Example 3 ## |
49 | 67 | x = np.arange(0, 1, .01)
|
50 |
| -f = figure(figsize=(6, 6)) |
| 68 | +f = plt.figure(figsize=(6, 6)) |
51 | 69 | f.text(0.5, 0.975, 'The new formatter, no numerical offset',
|
52 | 70 | horizontalalignment='center',
|
53 | 71 | verticalalignment='top')
|
| 72 | + |
54 | 73 | plt.subplot(221)
|
55 | 74 | plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
|
56 |
| -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
57 |
| -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
| 75 | +ax1 = plt.gca() |
| 76 | +ax1.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
| 77 | +ax1.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
| 78 | + |
58 | 79 | plt.subplot(222)
|
59 | 80 | plt.plot(x * 1e5, x * 1e-4)
|
60 |
| -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
61 |
| -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
| 81 | +ax2 = plt.gca() |
| 82 | +ax2.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
| 83 | +ax2.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
| 84 | + |
62 | 85 | plt.subplot(223)
|
63 | 86 | plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
|
64 |
| -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
65 |
| -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
| 87 | +ax3 = plt.gca() |
| 88 | +ax3.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
| 89 | +ax3.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
| 90 | + |
66 | 91 | plt.subplot(224)
|
67 | 92 | plt.plot(-x * 1e5, -x * 1e-4)
|
68 |
| -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
69 |
| -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
| 93 | +ax4 = plt.gca() |
| 94 | +ax4.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
| 95 | +ax4.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) |
70 | 96 |
|
| 97 | +## Example 4 ## |
71 | 98 | x = np.arange(0, 1, .01)
|
72 |
| -f = figure(figsize=(6, 6)) |
| 99 | +f = plt.figure(figsize=(6, 6)) |
73 | 100 | f.text(0.5, 0.975, 'The new formatter, with mathtext',
|
74 | 101 | horizontalalignment='center',
|
75 | 102 | verticalalignment='top')
|
76 | 103 | plt.subplot(221)
|
77 | 104 | plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
|
78 |
| -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
79 |
| -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
| 105 | +ax1 = plt.gca() |
| 106 | +ax1.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
| 107 | +ax1.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
| 108 | + |
80 | 109 | plt.subplot(222)
|
81 | 110 | plt.plot(x * 1e5, x * 1e-4)
|
82 |
| -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
83 |
| -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
| 111 | +ax2 = plt.gca() |
| 112 | +ax2.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
| 113 | +ax2.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
| 114 | + |
84 | 115 | plt.subplot(223)
|
85 | 116 | plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
|
86 |
| -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
87 |
| -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
| 117 | +ax3 = plt.gca() |
| 118 | +ax3.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
| 119 | +ax3.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
| 120 | + |
88 | 121 | plt.subplot(224)
|
89 | 122 | plt.plot(-x * 1e5, -x * 1e-4)
|
90 |
| -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
91 |
| -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
| 123 | +ax4 = plt.gca() |
| 124 | +ax4.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
| 125 | +ax4.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) |
92 | 126 | plt.show()
|
0 commit comments