Skip to content

Commit 21c508c

Browse files
authored
Merge pull request #216 from datacarpentry/redundant-code
Remove redundant code
2 parents 9bba1a5 + 86e4afc commit 21c508c

7 files changed

+5
-55
lines changed

_episodes/04-drawing.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ image = skimage.io.imread(fname="data/maize-seedlings.tif")
7070
7171
fig, ax = plt.subplots()
7272
plt.imshow(image)
73-
plt.show()
7473
~~~
7574
{: .language-python}
7675

@@ -118,7 +117,6 @@ mask[rr, cc] = False
118117
# Display mask image
119118
fig, ax = plt.subplots()
120119
plt.imshow(mask, cmap="gray")
121-
plt.show()
122120
~~~
123121
{: .language-python}
124122

@@ -219,7 +217,6 @@ The function returns the rectangle as row (`rr`) and column (`cc`) coordinate ar
219217
> > # Display the image
220218
> > fig, ax = plt.subplots()
221219
> > plt.imshow(image)
222-
> > plt.show()
223220
> > ~~~
224221
> > {: .language-python}
225222
> >
@@ -250,7 +247,6 @@ The function returns the rectangle as row (`rr`) and column (`cc`) coordinate ar
250247
> > # display the results
251248
> > fig, ax = plt.subplots()
252249
> > plt.imshow(image)
253-
> > plt.show()
254250
> > ~~~
255251
> > {: .language-python}
256252
> >
@@ -300,7 +296,6 @@ The function returns the rectangle as row (`rr`) and column (`cc`) coordinate ar
300296
> > # display the results
301297
> > fig, ax = plt.subplots()
302298
> > plt.imshow(image)
303-
> > plt.show()
304299
> > ~~~
305300
> > {: .language-python}
306301
> {: .solution}
@@ -362,7 +357,6 @@ Then, we display the masked image.
362357
~~~
363358
fig, ax = plt.subplots()
364359
plt.imshow(image)
365-
plt.show()
366360
~~~
367361
{: .language-python}
368362
@@ -408,7 +402,6 @@ The resulting masked image should look like this:
408402
> > # Display the result
409403
> > fig, ax = plt.subplots()
410404
> > plt.imshow(image)
411-
> > plt.show()
412405
> > ~~~
413406
> > {: .language-python}
414407
> {: .solution}
@@ -425,7 +418,6 @@ The resulting masked image should look like this:
425418
> # Display the image
426419
> fig, ax = plt.subplots()
427420
> plt.imshow(image)
428-
> plt.show()
429421
> ~~~
430422
> {: .language-python}
431423
>
@@ -472,7 +464,6 @@ The resulting masked image should look like this:
472464
> > # display the result
473465
> > fig, ax = plt.subplots()
474466
> > plt.imshow(image)
475-
> > plt.show()
476467
> > ~~~
477468
> > {: .language-python}
478469
> >
@@ -541,7 +532,6 @@ The resulting masked image should look like this:
541532
> > # display the result
542533
> > fig, ax = plt.subplots()
543534
> > plt.imshow(image)
544-
> > plt.show()
545535
> > ~~~
546536
> > {: .language-python}
547537
> {: .solution}

_episodes/05-creating-histograms.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ image = skimage.io.imread(fname="data/plant-seedling.jpg", as_gray=True)
5757
# display the image
5858
fig, ax = plt.subplots()
5959
plt.imshow(image, cmap="gray")
60-
plt.show()
6160
~~~
6261
{: .language-python}
6362

@@ -123,7 +122,6 @@ plt.ylabel("pixel count")
123122
plt.xlim([0.0, 1.0]) # <- named arguments do not work here
124123
125124
plt.plot(bin_edges[0:-1], histogram) # <- or here
126-
plt.show()
127125
~~~
128126
{: .language-python}
129127

@@ -151,7 +149,6 @@ Finally, we create the histogram plot itself with
151149
We use the **left** bin edges as x-positions for the histogram values by
152150
indexing the `bin_edges` array to ignore the last value
153151
(the **right** edge of the last bin).
154-
Then we make it appear with `plt.show()`.
155152
When we run the program on this image of a plant seedling,
156153
it produces this histogram:
157154

@@ -202,7 +199,6 @@ it produces this histogram:
202199
> > # display the image
203200
> > fig, ax = plt.subplots()
204201
> > plt.imshow(image, cmap="gray")
205-
> > plt.show()
206202
> >
207203
> > # create mask here, using np.zeros() and skimage.draw.rectangle()
208204
> > mask = np.zeros(shape=image.shape, dtype="bool")
@@ -212,7 +208,6 @@ it produces this histogram:
212208
> > # display the mask
213209
> > fig, ax = plt.subplots()
214210
> > plt.imshow(mask, cmap="gray")
215-
> > plt.show()
216211
> >
217212
> > # mask the image and create the new histogram
218213
> > histogram, bin_edges = np.histogram(image[mask], bins=256, range=(0.0, 1.0))
@@ -226,7 +221,6 @@ it produces this histogram:
226221
> > plt.xlim([0.0, 1.0])
227222
> > plt.plot(bin_edges[0:-1], histogram)
228223
> >
229-
> > plt.show()
230224
> > ~~~
231225
> > {: .language-python}
232226
> >
@@ -252,7 +246,6 @@ image = skimage.io.imread(fname="data/plant-seedling.jpg")
252246
# display the image
253247
fig, ax = plt.subplots()
254248
plt.imshow(image)
255-
plt.show()
256249
~~~
257250
{: .language-python}
258251
@@ -282,8 +275,6 @@ for channel_id, c in zip(channel_ids, colors):
282275
plt.title("Color Histogram")
283276
plt.xlabel("Color value")
284277
plt.ylabel("Pixel count")
285-
286-
plt.show()
287278
~~~
288279
{: .language-python}
289280
@@ -381,7 +372,6 @@ Finally we label our axes and display the histogram, shown here:
381372
> # display the image
382373
> fig, ax = plt.subplots()
383374
> plt.imshow(image)
384-
> plt.show()
385375
> ~~~
386376
> {: .language-python}
387377
> ![Well plate image](../fig/wellplate-02.jpg)
@@ -422,7 +412,6 @@ Finally we label our axes and display the histogram, shown here:
422412
> > # validity of your mask
423413
> > fig, ax = plt.subplots()
424414
> > plt.imshow(masked_img)
425-
> > plt.show()
426415
> >
427416
> > # list to select colors of each channel line
428417
> > colors = ("red", "green", "blue")
@@ -444,7 +433,6 @@ Finally we label our axes and display the histogram, shown here:
444433
> > plt.xlabel("color value")
445434
> > plt.ylabel("pixel count")
446435
> >
447-
> > plt.show()
448436
> > ~~~
449437
> > {: .language-python}
450438
> {: .solution}

_episodes/06-blurring.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ image = skimage.io.imread(fname="data/gaussian-original.png")
241241
# display the image
242242
fig, ax = plt.subplots()
243243
plt.imshow(image)
244-
plt.show()
245244
~~~
246245
{: .language-python}
247246
![Original image](../data/gaussian-original.png)
@@ -279,7 +278,6 @@ Finally, we display the blurred image:
279278
# display blurred image
280279
fig, ax = plt.subplots()
281280
plt.imshow(blurred)
282-
plt.show()
283281
~~~
284282
{: .language-python}
285283
![Original image](../fig/gaussian-blurred.png)
@@ -325,7 +323,6 @@ plt.show()
325323
> > # display blurred image
326324
> > fig, ax = plt.subplots()
327325
> > plt.imshow(blurred)
328-
> > plt.show()
329326
> > ~~~
330327
> > {: .language-python}
331328
> >

_episodes/07-thresholding.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ image = skimage.io.imread("data/shapes-01.jpg")
6565
6666
fig, ax = plt.subplots()
6767
plt.imshow(image)
68-
plt.show()
6968
~~~
7069
{: .language-python}
7170

@@ -95,7 +94,6 @@ blurred_image = skimage.filters.gaussian(gray_image, sigma=1.0)
9594
9695
fig, ax = plt.subplots()
9796
plt.imshow(blurred_image, cmap="gray")
98-
plt.show()
9997
~~~
10098
{: .language-python}
10199

@@ -128,7 +126,6 @@ plt.title("Grayscale Histogram")
128126
plt.xlabel("grayscale value")
129127
plt.ylabel("pixels")
130128
plt.xlim(0, 1.0)
131-
plt.show()
132129
~~~
133130
{: .language-python}
134131

@@ -163,7 +160,6 @@ binary_mask = blurred_image < t
163160
164161
fig, ax = plt.subplots()
165162
plt.imshow(binary_mask, cmap="gray")
166-
plt.show()
167163
~~~
168164
{: .language-python}
169165

@@ -208,7 +204,6 @@ selection[~binary_mask] = 0
208204
209205
fig, ax = plt.subplots()
210206
plt.imshow(selection)
211-
plt.show()
212207
~~~
213208
{: .language-python}
214209

@@ -240,7 +235,6 @@ plt.show()
240235
> > plt.xlabel("gray value")
241236
> > plt.ylabel("pixel count")
242237
> > plt.xlim(0, 1.0)
243-
> > plt.show()
244238
> > ~~~
245239
> > {: .language-python}
246240
> >
@@ -269,7 +263,6 @@ plt.show()
269263
> >
270264
> > fig, ax = plt.subplots()
271265
> > plt.imshow(binary_mask, cmap="gray")
272-
> > plt.show()
273266
> > ~~~
274267
> > {: .language-python}
275268
> >
@@ -283,7 +276,6 @@ plt.show()
283276
> >
284277
> > fig, ax = plt.subplots()
285278
> > plt.imshow(selection)
286-
> > plt.show()
287279
> > ~~~
288280
> > {: .language-python}
289281
> >
@@ -318,7 +310,6 @@ image = skimage.io.imread(fname="data/maize-root-cluster.jpg")
318310

319311
fig, ax = plt.subplots()
320312
plt.imshow(image)
321-
plt.show()
322313
~~~
323314
{: .language-python}
324315
@@ -342,7 +333,6 @@ plt.title("Graylevel histogram")
342333
plt.xlabel("gray value")
343334
plt.ylabel("pixel count")
344335
plt.xlim(0, 1.0)
345-
plt.show()
346336
~~~
347337
{: .language-python}
348338
@@ -386,7 +376,6 @@ binary_mask = blurred_image > t
386376

387377
fig, ax = plt.subplots()
388378
plt.imshow(binary_mask, cmap="gray")
389-
plt.show()
390379
~~~
391380
{: .language-python}
392381
@@ -401,7 +390,6 @@ selection[~binary_mask] = 0
401390

402391
fig, ax = plt.subplots()
403392
plt.imshow(selection)
404-
plt.show()
405393
~~~
406394
{: .language-python}
407395
@@ -703,7 +691,6 @@ data/trial-293.jpg,0.13607895611702128
703691
> > plt.xlabel("gray value")
704692
> > plt.ylabel("pixel count")
705693
> > plt.xlim(0, 1.0)
706-
> > plt.show()
707694
> > ~~~
708695
> > {: .language-python}
709696
> >
@@ -724,7 +711,6 @@ data/trial-293.jpg,0.13607895611702128
724711
> >
725712
> > fig, ax = plt.subplots()
726713
> > plt.imshow(binary_mask, cmap="gray")
727-
> > plt.show()
728714
> > ~~~
729715
> > {: .language-python}
730716
> >

_episodes/08-connected-components.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ labeled_image, count = connected_components(filename="data/shapes-01.jpg", sigma
297297

298298
fig, ax = plt.subplots()
299299
plt.imshow(labeled_image)
300-
plt.axis("off")
301-
plt.show()
300+
plt.axis("off");
302301
~~~
303302
{: .language-python}
304303
@@ -361,8 +360,7 @@ colored_label_image = skimage.color.label2rgb(labeled_image, bg_label=0)
361360

362361
fig, ax = plt.subplots()
363362
plt.imshow(colored_label_image)
364-
plt.axis("off")
365-
plt.show()
363+
plt.axis("off");
366364
~~~
367365
{: .language-python}
368366
@@ -503,8 +501,7 @@ This will produce the output
503501
> > fig, ax = plt.subplots()
504502
> > plt.hist(object_areas)
505503
> > plt.xlabel("Area (pixels)")
506-
> > plt.ylabel("Number of objects")
507-
> > plt.show()
504+
> > plt.ylabel("Number of objects");
508505
> > ~~~
509506
> > {: .language-python}
510507
> >
@@ -694,8 +691,7 @@ This will produce the output
694691
> >
695692
> > fig, ax = plt.subplots()
696693
> > plt.imshow(colored_label_image)
697-
> > plt.axis("off")
698-
> > plt.show()
694+
> > plt.axis("off");
699695
> >
700696
> > print("Found", count, "objects in the image.")
701697
> > ~~~
@@ -740,8 +736,7 @@ This will produce the output
740736
> > im = plt.imshow(colored_area_image)
741737
> > cbar = fig.colorbar(im, ax=ax, shrink=0.85)
742738
> > cbar.ax.set_title("Area")
743-
> > plt.axis("off")
744-
> > plt.show()
739+
> > plt.axis("off");
745740
> > ~~~
746741
> > {: .language-python}
747742
> >

_episodes/09-challenges.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ and `data/colonies-03.tif`.
6868
> > # display the image
6969
> > fig, ax = plt.subplots()
7070
> > plt.imshow(bacteria_image)
71-
> > plt.show()
7271
> > ~~~
7372
> > {: .language-python}
7473
> >
@@ -84,7 +83,6 @@ and `data/colonies-03.tif`.
8483
> > # display the gray image
8584
> > fig, ax = plt.subplots()
8685
> > plt.imshow(gray_bacteria, cmap="gray")
87-
> > plt.show()
8886
> > ~~~
8987
> > {: .language-python}
9088
> >
@@ -101,7 +99,6 @@ and `data/colonies-03.tif`.
10199
> > plt.xlabel("gray value")
102100
> > plt.ylabel("pixel count")
103101
> > plt.xlim(0, 1.0)
104-
> > plt.show()
105102
> > ~~~
106103
> > {: .language-python}
107104
> >
@@ -117,7 +114,6 @@ and `data/colonies-03.tif`.
117114
> > mask = blurred_image < 0.2
118115
> > fig, ax = plt.subplots()
119116
> > plt.imshow(mask, cmap="gray")
120-
> > plt.show()
121117
> > ~~~
122118
> > {: .language-python}
123119
> >
@@ -146,7 +142,6 @@ and `data/colonies-03.tif`.
146142
> > # plot overlay
147143
> > fig, ax = plt.subplots()
148144
> > plt.imshow(summary_image)
149-
> > plt.show()
150145
> > ~~~
151146
> > {: .language-python}
152147
> >

0 commit comments

Comments
 (0)