Commit 9d4005e5 authored by Andrew Lonsdale's avatar Andrew Lonsdale
Browse files

Change MATLAB style plot calls to a more Pythonic style

parent 1307f50f
......@@ -554,22 +554,23 @@ from matplotlib import pyplot as plt
data = np.loadtxt(fname='inflammation-01.csv', delimiter=',')
plt.figure(figsize=(10.0, 3.0))
fig = plt.figure(figsize=(10.0, 3.0))
plt.subplot(1, 3, 1)
plt.ylabel('average')
plt.plot(data.mean(axis=0))
axes1 = fig.add_subplot(1, 3, 1)
axes2 = fig.add_subplot(1, 3, 2)
axes3 = fig.add_subplot(1, 3, 3)
plt.subplot(1, 3, 2)
plt.ylabel('max')
plt.plot(data.max(axis=0))
axes1.set_ylabel('average')
axes1.plot(data.mean(axis=0))
plt.subplot(1, 3, 3)
plt.ylabel('min')
plt.plot(data.min(axis=0))
axes2.set_ylabel('max')
axes2.plot(data.max(axis=0))
plt.tight_layout()
plt.show()
axes3.set_ylabel('min')
axes3.plot(data.min(axis=0))
fig.tight_layout()
fig.show()
~~~
![The Previous Plots as Subplots](fig/01-numpy_80_0.png)\
......@@ -581,7 +582,7 @@ that we're creating three sub-plots,
what to draw for each one,
and that we want a tight layout.
(Perversely,
if we leave out that call to `plt.tight_layout()`,
if we leave out that call to `fig.tight_layout()`,
the graphs will actually be squeezed together more closely.)
> ## Moving plots around {.challenge}
......
......@@ -306,22 +306,23 @@ for f in filenames:
data = np.loadtxt(fname=f, delimiter=',')
plt.figure(figsize=(10.0, 3.0))
fig = plt.figure(figsize=(10.0, 3.0))
plt.subplot(1, 3, 1)
plt.ylabel('average')
plt.plot(data.mean(axis=0))
axes1 = fig.add_subplot(1, 3, 1)
axes2 = fig.add_subplot(1, 3, 2)
axes3 = fig.add_subplot(1, 3, 3)
plt.subplot(1, 3, 2)
plt.ylabel('max')
plt.plot(data.max(axis=0))
axes1.set_ylabel('average')
axes1.plot(data.mean(axis=0))
plt.subplot(1, 3, 3)
plt.ylabel('min')
plt.plot(data.min(axis=0))
axes2.set_ylabel('max')
axes2.plot(data.max(axis=0))
plt.tight_layout()
plt.show()
axes3.set_ylabel('min')
axes3.plot(data.min(axis=0))
fig.tight_layout()
fig.show()
~~~
~~~ {.output}
......
......@@ -234,22 +234,23 @@ def analyze(filename):
data = np.loadtxt(fname=filename, delimiter=',')
plt.figure(figsize=(10.0, 3.0))
fig = plt.figure(figsize=(10.0, 3.0))
plt.subplot(1, 3, 1)
plt.ylabel('average')
plt.plot(data.mean(axis=0))
axes1 = fig.add_subplot(1, 3, 1)
axes2 = fig.add_subplot(1, 3, 2)
axes3 = fig.add_subplot(1, 3, 3)
plt.subplot(1, 3, 2)
plt.ylabel('max')
plt.plot(data.max(axis=0))
axes1.set_ylabel('average')
axes1.plot(data.mean(axis=0))
plt.subplot(1, 3, 3)
plt.ylabel('min')
plt.plot(data.min(axis=0))
axes2.set_ylabel('max')
axes2.plot(data.max(axis=0))
plt.tight_layout()
plt.show()
axes3.set_ylabel('min')
axes3.plot(data.min(axis=0))
fig.tight_layout()
fig.show()
~~~
and another function called `detectProblems` that checks for those systematics
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment