Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2a2dcc

Browse files
committed
Updated simple plot example to OO format
1 parent e0415f9 commit b2a2dcc

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

examples/pylab_examples/simple_plot.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@
77
import matplotlib.pyplot as plt
88
import numpy as np
99

10+
# Data for plotting
1011
t = np.arange(0.0, 2.0, 0.01)
1112
s = 1 + np.sin(2*np.pi*t)
12-
plt.plot(t, s)
1313

14-
plt.xlabel('time (s)')
15-
plt.ylabel('voltage (mV)')
16-
plt.title('About as simple as it gets, folks')
17-
plt.grid(True)
18-
plt.savefig("test.png")
14+
# Note that using plt.subplots below is equivilent to using
15+
# fig = plt.figure and then ax = fig.add_subplot(111)
16+
fig, ax = plt.subplots()
17+
ax.plot(t, s)
18+
19+
ax.set(xlabel='time (s)', ylabel='voltage (mV)',
20+
title='About as simple as it gets, folks')
21+
ax.grid()
22+
23+
fig.savefig("test.png")
1924
plt.show()
25+

0 commit comments

Comments
 (0)