Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e35dc89

Browse filesBrowse files
committed
restructured fig and axes
1 parent ddfe342 commit e35dc89
Copy full SHA for e35dc89

File tree

Expand file treeCollapse file tree

1 file changed

+25
-56
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+25
-56
lines changed

‎examples/pylab_examples/newscalarformatter_demo.py

Copy file name to clipboardExpand all lines: examples/pylab_examples/newscalarformatter_demo.py
+25-56Lines changed: 25 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,123 +4,92 @@
44

55
## Example 1 ##
66
x = np.arange(0, 1, .01)
7-
f = plt.figure(figsize=(6, 6))
8-
f.text(0.5, 0.975, 'The old formatter',
7+
fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6))
8+
fig.text(0.5, 0.975, 'The old formatter',
99
horizontalalignment='center', verticalalignment='top')
10-
11-
plt.subplot(221)
12-
plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
13-
ax1 = plt.gca()
10+
ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
1411
ax1.xaxis.set_major_formatter(OldScalarFormatter())
1512
ax1.yaxis.set_major_formatter(OldScalarFormatter())
1613

17-
plt.subplot(222)
18-
plt.plot(x * 1e5, x * 1e-4)
19-
ax2 = plt.gca()
14+
ax2.plot(x * 1e5, x * 1e-4)
2015
ax2.xaxis.set_major_formatter(OldScalarFormatter())
2116
ax2.yaxis.set_major_formatter(OldScalarFormatter())
2217

23-
plt.subplot(223)
24-
plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
25-
ax3 = plt.gca()
18+
ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
2619
ax3.xaxis.set_major_formatter(OldScalarFormatter())
2720
ax3.yaxis.set_major_formatter(OldScalarFormatter())
2821

29-
plt.subplot(224)
30-
plt.plot(-x * 1e5, -x * 1e-4)
22+
ax4.plot(-x * 1e5, -x * 1e-4)
3123
ax4 = plt.gca()
3224
ax4.xaxis.set_major_formatter(OldScalarFormatter())
3325
ax4.yaxis.set_major_formatter(OldScalarFormatter())
3426

3527
## Example 2 ##
3628
x = np.arange(0, 1, .01)
37-
f = plt.figure(figsize=(6, 6))
38-
f.text(0.5, 0.975, 'The new formatter, default settings',
29+
fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6))
30+
fig.text(0.5, 0.975, 'The new formatter, default settings',
3931
horizontalalignment='center',
4032
verticalalignment='top')
4133

42-
plt.subplot(221)
43-
plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
44-
ax1 = plt.gca()
34+
ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
4535
ax1.xaxis.set_major_formatter(ScalarFormatter())
4636
ax1.yaxis.set_major_formatter(ScalarFormatter())
4737

48-
plt.subplot(222)
49-
plt.plot(x * 1e5, x * 1e-4)
50-
ax2 = plt.gca()
38+
ax2.plot(x * 1e5, x * 1e-4)
5139
ax2.xaxis.set_major_formatter(ScalarFormatter())
5240
ax2.yaxis.set_major_formatter(ScalarFormatter())
5341

54-
plt.subplot(223)
55-
plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
56-
ax3 = plt.gca()
42+
ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
5743
ax3.xaxis.set_major_formatter(ScalarFormatter())
5844
ax3.yaxis.set_major_formatter(ScalarFormatter())
5945

60-
plt.subplot(224)
61-
plt.plot(-x * 1e5, -x * 1e-4)
62-
ax4 = plt.gca()
46+
ax4.plot(-x * 1e5, -x * 1e-4)
6347
ax4.xaxis.set_major_formatter(ScalarFormatter())
6448
ax4.yaxis.set_major_formatter(ScalarFormatter())
6549

6650
## Example 3 ##
6751
x = np.arange(0, 1, .01)
68-
f = plt.figure(figsize=(6, 6))
69-
f.text(0.5, 0.975, 'The new formatter, no numerical offset',
52+
fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6))
53+
fig.text(0.5, 0.975, 'The new formatter, no numerical offset',
7054
horizontalalignment='center',
7155
verticalalignment='top')
7256

73-
plt.subplot(221)
74-
plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
75-
ax1 = plt.gca()
57+
ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
7658
ax1.xaxis.set_major_formatter(ScalarFormatter(useOffset=False))
7759
ax1.yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
7860

79-
plt.subplot(222)
80-
plt.plot(x * 1e5, x * 1e-4)
81-
ax2 = plt.gca()
61+
ax2.plot(x * 1e5, x * 1e-4)
8262
ax2.xaxis.set_major_formatter(ScalarFormatter(useOffset=False))
8363
ax2.yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
8464

85-
plt.subplot(223)
86-
plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
87-
ax3 = plt.gca()
65+
ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
8866
ax3.xaxis.set_major_formatter(ScalarFormatter(useOffset=False))
8967
ax3.yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
9068

91-
plt.subplot(224)
92-
plt.plot(-x * 1e5, -x * 1e-4)
93-
ax4 = plt.gca()
69+
ax4.plot(-x * 1e5, -x * 1e-4)
9470
ax4.xaxis.set_major_formatter(ScalarFormatter(useOffset=False))
9571
ax4.yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
9672

9773
## Example 4 ##
9874
x = np.arange(0, 1, .01)
99-
f = plt.figure(figsize=(6, 6))
100-
f.text(0.5, 0.975, 'The new formatter, with mathtext',
75+
fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6))
76+
fig.text(0.5, 0.975, 'The new formatter, with mathtext',
10177
horizontalalignment='center',
10278
verticalalignment='top')
103-
plt.subplot(221)
104-
plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
105-
ax1 = plt.gca()
79+
80+
ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
10681
ax1.xaxis.set_major_formatter(ScalarFormatter(useMathText=True))
10782
ax1.yaxis.set_major_formatter(ScalarFormatter(useMathText=True))
10883

109-
plt.subplot(222)
110-
plt.plot(x * 1e5, x * 1e-4)
111-
ax2 = plt.gca()
84+
ax2.plot(x * 1e5, x * 1e-4)
11285
ax2.xaxis.set_major_formatter(ScalarFormatter(useMathText=True))
11386
ax2.yaxis.set_major_formatter(ScalarFormatter(useMathText=True))
11487

115-
plt.subplot(223)
116-
plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
117-
ax3 = plt.gca()
88+
ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
11889
ax3.xaxis.set_major_formatter(ScalarFormatter(useMathText=True))
11990
ax3.yaxis.set_major_formatter(ScalarFormatter(useMathText=True))
12091

121-
plt.subplot(224)
122-
plt.plot(-x * 1e5, -x * 1e-4)
123-
ax4 = plt.gca()
92+
ax4.plot(-x * 1e5, -x * 1e-4)
12493
ax4.xaxis.set_major_formatter(ScalarFormatter(useMathText=True))
12594
ax4.yaxis.set_major_formatter(ScalarFormatter(useMathText=True))
12695
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.