8000 Merge pull request #17340 from asafmaman101/same-fig-creation-method · matplotlib/matplotlib@36bc7da · GitHub
[go: up one dir, main page]

Skip to content

Commit 36bc7da

Browse files
authored
Merge pull request #17340 from asafmaman101/same-fig-creation-method
convert some sample plots to use plt.subplots() instead of other methods
2 parents cf95c21 + 820bbdf commit 36bc7da

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

examples/pie_and_polar_charts/polar_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
r = np.arange(0, 2, 0.01)
1313
theta = 2 * np.pi * r
1414

15-
ax = plt.subplot(111, projection='polar')
15+
fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
1616
ax.plot(theta, r)
1717
ax.set_rmax(2)
1818
ax.set_rticks([0.5, 1, 1.5, 2]) # Less radial ticks

examples/subplots_axes_and_figures/subplot.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,36 @@
88
import numpy as np
99
import matplotlib.pyplot as plt
1010

11+
###############################################################################
12+
13+
x1 = np.linspace(0.0, 5.0)
14+
x2 = np.linspace(0.0, 2.0)
15+
16+
y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)
17+
y2 = np.cos(2 * np.pi * x2)
18+
19+
fig, (ax1, ax2) = plt.subplots(2, 1)
20+
fig.suptitle('A tale of 2 subplots')
21+
22+
ax1.plot(x1, y1, 'o-')
23+
ax1.set_ylabel('Damped oscillation')
24+
25+
ax2.plot(x2, y2, '.-')
26+
ax2.set_xlabel('time (s)')
27+
ax2.set_ylabel('Undamped')
28+
29+
plt.show()
30+
31+
#############################################################################
32+
#
33+
#
34+
# Alternative Method For Creating Multiple Plots
35+
# """"""""""""""""""""""""""""""""""""""""""""""
36+
#
37+
# Subplots can also be generated using `~.pyplot.subplot()` \
38+
# as in the following example:
39+
#
40+
1141

1242
x1 = np.linspace(0.0, 5.0)
1343
x2 = np.linspace(0.0, 2.0)

0 commit comments

Comments
 (0)
0