Skip to content

Commit 31f5991

Browse files
authored
Merge pull request #368 from digitaltxtlab/04-comp-stat-solution
Generate Composite Statistics - solution
2 parents a237664 + 5ff7584 commit 31f5991

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

_episodes/04-files.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,40 @@ where the maxima are a bit less regular, but the minima are consistently zero.
148148
>
149149
> Then use pyplot to generate average, max, and min for all patients.
150150
>
151+
> > ## Solution
152+
> > ~~~
153+
> > import glob
154+
> > import numpy
155+
> > import matplotlib.pyplot
156+
> >
157+
> > filenames = glob.glob('data/inflammation*.csv')
158+
> > composite_data = numpy.zeros((60,40))
159+
> >
160+
> > for f in filenames:
161+
> > data = numpy.loadtxt(fname = f, delimiter=',')
162+
> > composite_data += data
163+
> >
164+
> > composite_data/=len(filenames)
165+
> >
166+
> > fig = matplotlib.pyplot.figure(figsize=(10.0, 3.0))
167+
> >
168+
> > axes1 = fig.add_subplot(1, 3, 1)
169+
> > axes2 = fig.add_subplot(1, 3, 2)
170+
> > axes3 = fig.add_subplot(1, 3, 3)
171+
> >
172+
> > axes1.set_ylabel('average')
173+
> > axes1.plot(numpy.mean(composite_data, axis=0))
174+
> >
175+
> > axes2.set_ylabel('max')
176+
> > axes2.plot(numpy.max(composite_data, axis=0))
177+
> >
178+
> > axes3.set_ylabel('min')
179+
> > axes3.plot(numpy.min(composite_data, axis=0))
180+
> >
181+
> > fig.tight_layout()
182+
> >
183+
> > matplotlib.pyplot.show()
184+
> > ~~~
185+
> > {: .python}
186+
>{: .solution}
151187
{: .challenge}

0 commit comments

Comments
 (0)