diff --git a/doc/examples/applications/plot_coins_segmentation.py b/doc/examples/applications/plot_coins_segmentation.py index fe165760..404c1b98 100644 --- a/doc/examples/applications/plot_coins_segmentation.py +++ b/doc/examples/applications/plot_coins_segmentation.py @@ -35,13 +35,15 @@ background with the coins: """ -fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3)) +fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3), sharex=True, sharey=True) ax1.imshow(coins > 100, cmap=plt.cm.gray, interpolation='nearest') ax1.set_title('coins > 100') ax1.axis('off') +ax1.set_adjustable('box-forced') ax2.imshow(coins > 150, cmap=plt.cm.gray, interpolation='nearest') ax2.set_title('coins > 150') ax2.axis('off') +ax2.set_adjustable('box-forced') margins = dict(hspace=0.01, wspace=0.01, top=1, bottom=0, left=0, right=1) fig.subplots_adjust(**margins) @@ -162,12 +164,14 @@ segmentation = ndi.binary_fill_holes(segmentation - 1) labeled_coins, _ = ndi.label(segmentation) image_label_overlay = label2rgb(labeled_coins, image=coins) -fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3)) +fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3), sharex=True, sharey=True) ax1.imshow(coins, cmap=plt.cm.gray, interpolation='nearest') ax1.contour(segmentation, [0.5], linewidths=1.2, colors='y') ax1.axis('off') +ax1.set_adjustable('box-forced') ax2.imshow(image_label_overlay, interpolation='nearest') ax2.axis('off') +ax2.set_adjustable('box-forced') fig.subplots_adjust(**margins) diff --git a/doc/examples/applications/plot_morphology.py b/doc/examples/applications/plot_morphology.py index 68ecc6d6..33246793 100644 --- a/doc/examples/applications/plot_morphology.py +++ b/doc/examples/applications/plot_morphology.py @@ -42,13 +42,15 @@ Let's also define a convenience function for plotting comparisons: def plot_comparison(original, filtered, filter_name): - fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4)) + fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4), sharex=True, sharey=True) ax1.imshow(original, cmap=plt.cm.gray) ax1.set_title('original') ax1.axis('off') + ax1.set_adjustable('box-forced') ax2.imshow(filtered, cmap=plt.cm.gray) ax2.set_title(filter_name) ax2.axis('off') + ax2.set_adjustable('box-forced') """ Erosion diff --git a/doc/examples/applications/plot_rank_filters.py b/doc/examples/applications/plot_rank_filters.py index e2dbd71b..b1e0cc79 100644 --- a/doc/examples/applications/plot_rank_filters.py +++ b/doc/examples/applications/plot_rank_filters.py @@ -70,24 +70,31 @@ noisy_image = img_as_ubyte(data.camera()) noisy_image[noise > 0.99] = 255 noisy_image[noise < 0.01] = 0 -fig, ax = plt.subplots(2, 2, figsize=(10, 7)) +fig, ax = plt.subplots(2, 2, figsize=(10, 7), sharex=True, sharey=True) ax1, ax2, ax3, ax4 = ax.ravel() ax1.imshow(noisy_image, vmin=0, vmax=255, cmap=plt.cm.gray) ax1.set_title('Noisy image') ax1.axis('off') +ax1.set_adjustable('box-forced') ax2.imshow(median(noisy_image, disk(1)), vmin=0, vmax=255, cmap=plt.cm.gray) ax2.set_title('Median $r=1$') ax2.axis('off') +ax2.set_adjustable('box-forced') + ax3.imshow(median(noisy_image, disk(5)), vmin=0, vmax=255, cmap=plt.cm.gray) ax3.set_title('Median $r=5$') ax3.axis('off') +ax3.set_adjustable('box-forced') + ax4.imshow(median(noisy_image, disk(20)), vmin=0, vmax=255, cmap=plt.cm.gray) ax4.set_title('Median $r=20$') ax4.axis('off') +ax4.set_adjustable('box-forced') + """ @@ -109,17 +116,19 @@ image. from skimage.filters.rank import mean -fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[10, 7]) +fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[10, 7], sharex=True, sharey=True) loc_mean = mean(noisy_image, disk(10)) ax1.imshow(noisy_image, vmin=0, vmax=255, cmap=plt.cm.gray) ax1.set_title('Original') ax1.axis('off') +ax1.set_adjustable('box-forced') ax2.imshow(loc_mean, vmin=0, vmax=255, cmap=plt.cm.gray) ax2.set_title('Local mean $r=10$') ax2.axis('off') +ax2.set_adjustable('box-forced') """ @@ -143,22 +152,26 @@ noisy_image = img_as_ubyte(data.camera()) bilat = mean_bilateral(noisy_image.astype(np.uint16), disk(20), s0=10, s1=10) -fig, ax = plt.subplots(2, 2, figsize=(10, 7)) +fig, ax = plt.subplots(2, 2, figsize=(10, 7), sharex='row', sharey='row') ax1, ax2, ax3, ax4 = ax.ravel() ax1.imshow(noisy_image, cmap=plt.cm.gray) ax1.set_title('Original') ax1.axis('off') +ax1.set_adjustable('box-forced') ax2.imshow(bilat, cmap=plt.cm.gray) ax2.set_title('Bilateral mean') ax2.axis('off') +ax2.set_adjustable('box-forced') ax3.imshow(noisy_image[200:350, 350:450], cmap=plt.cm.gray) ax3.axis('off') +ax3.set_adjustable('box-forced') ax4.imshow(bilat[200:350, 350:450], cmap=plt.cm.gray) ax4.axis('off') +ax4.set_adjustable('box-forced') """ @@ -236,15 +249,17 @@ noisy_image = img_as_ubyte(data.camera()) auto = autolevel(noisy_image.astype(np.uint16), disk(20)) -fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[10, 7]) +fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[10, 7], sharex=True, sharey=True) ax1.imshow(noisy_image, cmap=plt.cm.gray) ax1.set_title('Original') ax1.axis('off') +ax1.set_adjustable('box-forced') ax2.imshow(auto, cmap=plt.cm.gray) ax2.set_title('Local autolevel') ax2.axis('off') +ax2.set_adjustable('box-forced') """ @@ -271,22 +286,29 @@ loc_perc_autolevel1 = autolevel_percentile(image, selem=selem, p0=.01, p1=.99) loc_perc_autolevel2 = autolevel_percentile(image, selem=selem, p0=.05, p1=.95) loc_perc_autolevel3 = autolevel_percentile(image, selem=selem, p0=.1, p1=.9) -fig, axes = plt.subplots(nrows=3, figsize=(7, 8)) +fig, axes = plt.subplots(nrows=3, ncols=2, figsize=(7, 8), sharex=True, sharey=True) ax0, ax1, ax2 = axes plt.gray() -ax0.imshow(np.hstack((image, loc_autolevel)), cmap=plt.cm.gray) -ax0.set_title('Original / auto-level') +title_list = ['Original', + 'auto_level', + 'auto-level 0%', + 'auto-level 1%', + 'auto-level 5%', + 'auto-level 10%'] +image_list = [image, + loc_autolevel, + loc_perc_autolevel0, + loc_perc_autolevel1, + loc_perc_autolevel2, + loc_perc_autolevel3] +axes_list = axes.ravel().tolist() -ax1.imshow( - np.hstack((loc_perc_autolevel0, loc_perc_autolevel1)), vmin=0, vmax=255) -ax1.set_title('Percentile auto-level 0%,1%') -ax2.imshow( - np.hstack((loc_perc_autolevel2, loc_perc_autolevel3)), vmin=0, vmax=255) -ax2.set_title('Percentile auto-level 5% and 10%') - -for ax in axes: - ax.axis('off') +for i in range(0,len(image_list)): + axes_list[i].imshow(image_list[i], cmap=plt.cm.gray, vmin=0, vmax=255) + axes_list[i].set_title(title_list[i]) + axes_list[i].axis('off') + axes_list[i].set_adjustable('box-forced') """ @@ -304,22 +326,26 @@ noisy_image = img_as_ubyte(data.camera()) enh = enhance_contrast(noisy_image, disk(5)) -fig, ax = plt.subplots(2, 2, figsize=[10, 7]) +fig, ax = plt.subplots(2, 2, figsize=[10, 7], sharex='row', sharey='row') ax1, ax2, ax3, ax4 = ax.ravel() ax1.imshow(noisy_image, cmap=plt.cm.gray) ax1.set_title('Original') ax1.axis('off') +ax1.set_adjustable('box-forced') ax2.imshow(enh, cmap=plt.cm.gray) ax2.set_title('Local morphological contrast enhancement') ax2.axis('off') +ax2.set_adjustable('box-forced') ax3.imshow(noisy_image[200:350, 350:450], cmap=plt.cm.gray) ax3.axis('off') +ax3.set_adjustable('box-forced') ax4.imshow(enh[200:350, 350:450], cmap=plt.cm.gray) ax4.axis('off') +ax4.set_adjustable('box-forced') """ @@ -336,22 +362,22 @@ noisy_image = img_as_ubyte(data.camera()) penh = enhance_contrast_percentile(noisy_image, disk(5), p0=.1, p1=.9) -fig, ax = plt.subplots(2, 2, figsize=[10, 7]) +fig, ax = plt.subplots(2, 2, figsize=[10, 7], sharex='row', sharey='row') ax1, ax2, ax3, ax4 = ax.ravel() ax1.imshow(noisy_image, cmap=plt.cm.gray) ax1.set_title('Original') -ax1.axis('off') ax2.imshow(penh, cmap=plt.cm.gray) ax2.set_title('Local percentile morphological\n contrast enhancement') -ax2.axis('off') ax3.imshow(noisy_image[200:350, 350:450], cmap=plt.cm.gray) -ax3.axis('off') ax4.imshow(penh[200:350, 350:450], cmap=plt.cm.gray) -ax4.axis('off') + +for ax in ax.ravel(): + ax.axis('off') + ax.set_adjustable('box-forced') """ @@ -393,24 +419,24 @@ loc_otsu = p8 >= t_loc_otsu t_glob_otsu = threshold_otsu(p8) glob_otsu = p8 >= t_glob_otsu -fig, ax = plt.subplots(2, 2) +fig, ax = plt.subplots(2, 2, sharex=True, sharey=True) ax1, ax2, ax3, ax4 = ax.ravel() fig.colorbar(ax1.imshow(p8, cmap=plt.cm.gray), ax=ax1) ax1.set_title('Original') -ax1.axis('off') fig.colorbar(ax2.imshow(t_loc_otsu, cmap=plt.cm.gray), ax=ax2) ax2.set_title('Local Otsu ($r=%d$)' % radius) -ax2.axis('off') ax3.imshow(p8 >= t_loc_otsu, cmap=plt.cm.gray) ax3.set_title('Original >= local Otsu' % t_glob_otsu) -ax3.axis('off') ax4.imshow(glob_otsu, cmap=plt.cm.gray) ax4.set_title('Global Otsu ($t=%d$)' % t_glob_otsu) -ax4.axis('off') + +for ax in ax.ravel(): + ax.axis('off') + ax.set_adjustable('box-forced') """ @@ -429,15 +455,17 @@ m = (np.tile(x, (n, 1)) * np.linspace(0.1, 1, n) * 128 + 128).astype(np.uint8) radius = 10 t = rank.otsu(m, disk(radius)) -fig, (ax1, ax2) = plt.subplots(1, 2) +fig, (ax1, ax2) = plt.subplots(1, 2, sharex=True, sharey=True) ax1.imshow(m) ax1.set_title('Original') ax1.axis('off') +ax1.set_adjustable('box-forced') ax2.imshow(m >= t, interpolation='nearest') ax2.set_title('Local Otsu ($r=%d$)' % radius) ax2.axis('off') +ax2.set_adjustable('box-forced') """ @@ -468,25 +496,24 @@ opening = minimum(maximum(noisy_image, disk(5)), disk(5)) grad = gradient(noisy_image, disk(5)) # display results -fig, ax = plt.subplots(2, 2, figsize=[10, 7]) +fig, ax = plt.subplots(2, 2, figsize=[10, 7], sharex=True, sharey=True) ax1, ax2, ax3, ax4 = ax.ravel() ax1.imshow(noisy_image, cmap=plt.cm.gray) ax1.set_title('Original') -ax1.axis('off') ax2.imshow(closing, cmap=plt.cm.gray) ax2.set_title('Gray-level closing') -ax2.axis('off') ax3.imshow(opening, cmap=plt.cm.gray) ax3.set_title('Gray-level opening') -ax3.axis('off') ax4.imshow(grad, cmap=plt.cm.gray) ax4.set_title('Morphological gradient') -ax4.axis('off') +for ax in ax.ravel(): + ax.axis('off') + ax.set_adjustable('box-forced') """ .. image:: PLOT2RST.current_figure @@ -518,15 +545,17 @@ import matplotlib.pyplot as plt image = data.camera() -fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4)) +fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4), sharex=True, sharey=True) fig.colorbar(ax1.imshow(image, cmap=plt.cm.gray), ax=ax1) ax1.set_title('Image') ax1.axis('off') +ax1.set_adjustable('box-forced') fig.colorbar(ax2.imshow(entropy(image, disk(5)), cmap=plt.cm.jet), ax=ax2) ax2.set_title('Entropy') ax2.axis('off') +ax2.set_adjustable('box-forced') """ @@ -680,10 +709,15 @@ Comparison of outcome of the three methods: """ -fig, ax = plt.subplots() -ax.imshow(np.hstack((rc, rndi))) -ax.set_title('filters.rank.median vs. scipy.ndimage.percentile') -ax.axis('off') +fig, (ax0, ax1) = plt.subplots(ncols=2, sharex=True, sharey=True) +ax0.set_title('filters.rank.median') +ax0.imshow(rc) +ax0.axis('off') +ax0.set_adjustable('box-forced') +ax1.set_title('scipy.ndimage.percentile') +ax1.imshow(rndi) +ax1.axis('off') +ax1.set_adjustable('box-forced') """ .. image:: PLOT2RST.current_figure diff --git a/doc/examples/plot_adapt_rgb.py b/doc/examples/plot_adapt_rgb.py index d267cc4a..24d8f078 100644 --- a/doc/examples/plot_adapt_rgb.py +++ b/doc/examples/plot_adapt_rgb.py @@ -48,8 +48,8 @@ import matplotlib.pyplot as plt image = data.astronaut() fig = plt.figure(figsize=(14, 7)) -ax_each = fig.add_subplot(121) -ax_hsv = fig.add_subplot(122) +ax_each = fig.add_subplot(121, adjustable='box-forced') +ax_hsv = fig.add_subplot(122, sharex=ax_each, sharey=ax_each, adjustable='box-forced') # We use 1 - sobel_each(image) # but this will not work if image is not normalized @@ -107,7 +107,7 @@ def sobel_gray(image): return filters.sobel(image) fig = plt.figure(figsize=(7, 7)) -ax = fig.add_subplot(111) +ax = fig.add_subplot(111, sharex=ax_each, sharey=ax_each, adjustable='box-forced') # We use 1 - sobel_gray(image) # but this will not work if image is not normalized diff --git a/doc/examples/plot_blob.py b/doc/examples/plot_blob.py index 33cc44c2..bb5dd089 100644 --- a/doc/examples/plot_blob.py +++ b/doc/examples/plot_blob.py @@ -61,8 +61,12 @@ titles = ['Laplacian of Gaussian', 'Difference of Gaussian', 'Determinant of Hessian'] sequence = zip(blobs_list, colors, titles) + +fig,axes = plt.subplots(1, 3, sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) +axes = axes.ravel() for blobs, color, title in sequence: - fig, ax = plt.subplots(1, 1) + ax = axes[0] + axes = axes[1:] ax.set_title(title) ax.imshow(image, interpolation='nearest') for blob in blobs: diff --git a/doc/examples/plot_canny.py b/doc/examples/plot_canny.py index 7d770787..06d2a05d 100644 --- a/doc/examples/plot_canny.py +++ b/doc/examples/plot_canny.py @@ -35,7 +35,7 @@ edges1 = feature.canny(im) edges2 = feature.canny(im, sigma=3) # display results -fig, (ax1, ax2, ax3) = plt.subplots(nrows=1, ncols=3, figsize=(8, 3)) +fig, (ax1, ax2, ax3) = plt.subplots(nrows=1, ncols=3, figsize=(8, 3), sharex=True, sharey=True) ax1.imshow(im, cmap=plt.cm.jet) ax1.axis('off') diff --git a/doc/examples/plot_circular_elliptical_hough_transform.py b/doc/examples/plot_circular_elliptical_hough_transform.py index 684ad30b..5d5a8b2e 100755 --- a/doc/examples/plot_circular_elliptical_hough_transform.py +++ b/doc/examples/plot_circular_elliptical_hough_transform.py @@ -138,7 +138,7 @@ image_rgb[cy, cx] = (0, 0, 255) edges = color.gray2rgb(edges) edges[cy, cx] = (250, 0, 0) -fig2, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, figsize=(8, 4)) +fig2, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, figsize=(8, 4), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax1.set_title('Original picture') ax1.imshow(image_rgb) diff --git a/doc/examples/plot_denoise.py b/doc/examples/plot_denoise.py index 1313bc04..f39591d2 100644 --- a/doc/examples/plot_denoise.py +++ b/doc/examples/plot_denoise.py @@ -38,7 +38,7 @@ astro = astro[220:300, 220:320] noisy = astro + 0.6 * astro.std() * np.random.random(astro.shape) noisy = np.clip(noisy, 0, 1) -fig, ax = plt.subplots(nrows=2, ncols=3, figsize=(8, 5)) +fig, ax = plt.subplots(nrows=2, ncols=3, figsize=(8, 5), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) plt.gray() diff --git a/doc/examples/plot_edge_filter.py b/doc/examples/plot_edge_filter.py index 96b654a8..7ad1a6eb 100644 --- a/doc/examples/plot_edge_filter.py +++ b/doc/examples/plot_edge_filter.py @@ -19,7 +19,7 @@ image = camera() edge_roberts = roberts(image) edge_sobel = sobel(image) -fig, (ax0, ax1) = plt.subplots(ncols=2) +fig, (ax0, ax1) = plt.subplots(ncols=2, sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax0.imshow(edge_roberts, cmap=plt.cm.gray) ax0.set_title('Roberts Edge Detection') @@ -66,7 +66,7 @@ diff_scharr_prewitt = edge_scharr - edge_prewitt diff_scharr_sobel = edge_scharr - edge_sobel max_diff = np.max(np.maximum(diff_scharr_prewitt, diff_scharr_sobel)) -fig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2) +fig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2, sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax0.imshow(img, cmap=plt.cm.gray) ax0.set_title('Original image') diff --git a/doc/examples/plot_entropy.py b/doc/examples/plot_entropy.py index f33f26ff..3ca5c94e 100644 --- a/doc/examples/plot_entropy.py +++ b/doc/examples/plot_entropy.py @@ -17,7 +17,7 @@ from skimage.util import img_as_ubyte image = img_as_ubyte(data.camera()) -fig, (ax0, ax1) = plt.subplots(ncols=2, figsize=(10, 4)) +fig, (ax0, ax1) = plt.subplots(ncols=2, figsize=(10, 4), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) img0 = ax0.imshow(image, cmap=plt.cm.gray) ax0.set_title('Image') diff --git a/doc/examples/plot_equalize.py b/doc/examples/plot_equalize.py index 2d04e22a..2289e270 100644 --- a/doc/examples/plot_equalize.py +++ b/doc/examples/plot_equalize.py @@ -40,6 +40,7 @@ def plot_img_and_hist(img, axes, bins=256): # Display image ax_img.imshow(img, cmap=plt.cm.gray) ax_img.set_axis_off() + ax_img.set_adjustable('box-forced') # Display histogram ax_hist.hist(img.ravel(), bins=bins, histtype='step', color='black') @@ -70,7 +71,13 @@ img_eq = exposure.equalize_hist(img) img_adapteq = exposure.equalize_adapthist(img, clip_limit=0.03) # Display results -fig, axes = plt.subplots(nrows=2, ncols=4, figsize=(8, 5)) +fig = plt.figure(figsize=(8, 5)) +axes = np.zeros((2,4), dtype=np.object) +axes[0,0] = fig.add_subplot(2, 4, 1) +for i in range(1,4): + axes[0,i] = fig.add_subplot(2, 4, 1+i, sharex=axes[0,0], sharey=axes[0,0]) +for i in range(0,4): + axes[1,i] = fig.add_subplot(2, 4, 5+i) ax_img, ax_hist, ax_cdf = plot_img_and_hist(img, axes[:, 0]) ax_img.set_title('Low contrast image') diff --git a/doc/examples/plot_hog.py b/doc/examples/plot_hog.py index 15b279bd..ab71bb36 100644 --- a/doc/examples/plot_hog.py +++ b/doc/examples/plot_hog.py @@ -90,11 +90,12 @@ image = color.rgb2gray(data.astronaut()) fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16), cells_per_block=(1, 1), visualise=True) -fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4)) +fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4), sharex=True, sharey=True) ax1.axis('off') ax1.imshow(image, cmap=plt.cm.gray) ax1.set_title('Input image') +ax1.set_adjustable('box-forced') # Rescale histogram for better display hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 0.02)) @@ -102,4 +103,5 @@ hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 0.02)) ax2.axis('off') ax2.imshow(hog_image_rescaled, cmap=plt.cm.gray) ax2.set_title('Histogram of Oriented Gradients') +ax1.set_adjustable('box-forced') plt.show() diff --git a/doc/examples/plot_holes_and_peaks.py b/doc/examples/plot_holes_and_peaks.py index 90af1cbe..23c119e8 100644 --- a/doc/examples/plot_holes_and_peaks.py +++ b/doc/examples/plot_holes_and_peaks.py @@ -21,16 +21,13 @@ image = data.moon() # Rescale image intensity so that we can see dim features. image = rescale_intensity(image, in_range=(50, 200)) - -# convenience function for plotting images -def imshow(image, title, **kwargs): - fig, ax = plt.subplots(figsize=(5, 4)) - ax.imshow(image, **kwargs) - ax.axis('off') - ax.set_title(title) +fig,ax = plt.subplots(2, 2, figsize=(5, 4), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) +ax = ax.ravel() -imshow(image, 'Original image') +ax[0].imshow(image) +ax[0].set_title('Original image') +ax[0].axis('off') """ .. image:: PLOT2RST.current_figure @@ -52,8 +49,9 @@ mask = image filled = reconstruction(seed, mask, method='erosion') -imshow(filled, 'after filling holes', vmin=image.min(), vmax=image.max()) - +ax[1].imshow(filled) +ax[1].set_title('after filling holes') +ax[1].axis('off') """ .. image:: PLOT2RST.current_figure @@ -63,8 +61,9 @@ isolate the dark regions by subtracting the reconstructed image from the original image. """ -imshow(image - filled, 'holes') -# plt.title('holes') +ax[2].imshow(image-filled) +ax[2].set_title('holes') +ax[2].axis('off') """ .. image:: PLOT2RST.current_figure @@ -79,7 +78,10 @@ intensity instead of the maximum. The remainder of the process is the same. seed = np.copy(image) seed[1:-1, 1:-1] = image.min() rec = reconstruction(seed, mask, method='dilation') -imshow(image - rec, 'peaks') + +ax[3].imshow(image-rec) +ax[3].set_title('peaks') +ax[3].axis('off') plt.show() """ diff --git a/doc/examples/plot_ihc_color_separation.py b/doc/examples/plot_ihc_color_separation.py index 3e297386..6191a800 100644 --- a/doc/examples/plot_ihc_color_separation.py +++ b/doc/examples/plot_ihc_color_separation.py @@ -26,7 +26,7 @@ from skimage.color import rgb2hed ihc_rgb = data.immunohistochemistry() ihc_hed = rgb2hed(ihc_rgb) -fig, axes = plt.subplots(2, 2, figsize=(7, 6)) +fig, axes = plt.subplots(2, 2, figsize=(7, 6), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax0, ax1, ax2, ax3 = axes.ravel() ax0.imshow(ihc_rgb) @@ -61,7 +61,9 @@ h = rescale_intensity(ihc_hed[:, :, 0], out_range=(0, 1)) d = rescale_intensity(ihc_hed[:, :, 2], out_range=(0, 1)) zdh = np.dstack((np.zeros_like(h), d, h)) -fig, ax = plt.subplots() +#fig, ax = plt.subplots() +fig = plt.figure() +ax = plt.subplot(1, 1, 1, sharex=ax0, sharey=ax0, adjustable='box-forced') ax.imshow(zdh) ax.set_title("Stain separated image (rescaled)") ax.axis('off') diff --git a/doc/examples/plot_join_segmentations.py b/doc/examples/plot_join_segmentations.py index 5fded86e..0ad7e57c 100644 --- a/doc/examples/plot_join_segmentations.py +++ b/doc/examples/plot_join_segmentations.py @@ -40,7 +40,7 @@ seg2 = slic(coins, n_segments=117, max_iter=160, sigma=1, compactness=0.75, segj = join_segmentations(seg1, seg2) # show the segmentations -fig, axes = plt.subplots(ncols=4, figsize=(9, 2.5)) +fig, axes = plt.subplots(ncols=4, figsize=(9, 2.5), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) axes[0].imshow(coins, cmap=plt.cm.gray, interpolation='nearest') axes[0].set_title('Image') diff --git a/doc/examples/plot_line_hough_transform.py b/doc/examples/plot_line_hough_transform.py index 7ee3f1f7..15464768 100644 --- a/doc/examples/plot_line_hough_transform.py +++ b/doc/examples/plot_line_hough_transform.py @@ -77,30 +77,30 @@ image[idx, idx] = 255 h, theta, d = hough_line(image) -fig, ax = plt.subplots(1, 3, figsize=(8, 4)) +fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8,4)) -ax[0].imshow(image, cmap=plt.cm.gray) -ax[0].set_title('Input image') -ax[0].axis('image') +ax1.imshow(image, cmap=plt.cm.gray) +ax1.set_title('Input image') +ax1.set_axis_off() -ax[1].imshow(np.log(1 + h), +ax2.imshow(np.log(1 + h), extent=[np.rad2deg(theta[-1]), np.rad2deg(theta[0]), d[-1], d[0]], cmap=plt.cm.gray, aspect=1/1.5) -ax[1].set_title('Hough transform') -ax[1].set_xlabel('Angles (degrees)') -ax[1].set_ylabel('Distance (pixels)') -ax[1].axis('image') +ax2.set_title('Hough transform') +ax2.set_xlabel('Angles (degrees)') +ax2.set_ylabel('Distance (pixels)') +ax2.axis('image') -ax[2].imshow(image, cmap=plt.cm.gray) +ax3.imshow(image, cmap=plt.cm.gray) rows, cols = image.shape for _, angle, dist in zip(*hough_line_peaks(h, theta, d)): y0 = (dist - 0 * np.cos(angle)) / np.sin(angle) y1 = (dist - cols * np.cos(angle)) / np.sin(angle) - ax[2].plot((0, cols), (y0, y1), '-r') -ax[2].axis((0, cols, rows, 0)) -ax[2].set_title('Detected lines') -ax[2].axis('image') + ax3.plot((0, cols), (y0, y1), '-r') +ax3.axis((0, cols, rows, 0)) +ax3.set_title('Detected lines') +ax3.set_axis_off() # Line finding, using the Probabilistic Hough Transform @@ -109,22 +109,25 @@ edges = canny(image, 2, 1, 25) lines = probabilistic_hough_line(edges, threshold=10, line_length=5, line_gap=3) -fig2, ax = plt.subplots(1, 3, figsize=(8, 3)) +fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8,4), sharex=True, sharey=True) -ax[0].imshow(image, cmap=plt.cm.gray) -ax[0].set_title('Input image') -ax[0].axis('image') +ax1.imshow(image, cmap=plt.cm.gray) +ax1.set_title('Input image') +ax1.set_axis_off() +ax1.set_adjustable('box-forced') -ax[1].imshow(edges, cmap=plt.cm.gray) -ax[1].set_title('Canny edges') -ax[1].axis('image') +ax2.imshow(edges, cmap=plt.cm.gray) +ax2.set_title('Canny edges') +ax2.set_axis_off() +ax2.set_adjustable('box-forced') -ax[2].imshow(edges * 0) +ax3.imshow(edges * 0) for line in lines: p0, p1 = line - ax[2].plot((p0[0], p1[0]), (p0[1], p1[1])) + ax3.plot((p0[0], p1[0]), (p0[1], p1[1])) -ax[2].set_title('Probabilistic Hough') -ax[2].axis('image') +ax3.set_title('Probabilistic Hough') +ax3.set_axis_off() +ax3.set_adjustable('box-forced') plt.show() diff --git a/doc/examples/plot_local_equalize.py b/doc/examples/plot_local_equalize.py index cce8fa42..194bfe6a 100644 --- a/doc/examples/plot_local_equalize.py +++ b/doc/examples/plot_local_equalize.py @@ -72,7 +72,14 @@ img_eq = rank.equalize(img, selem=selem) # Display results -fig, axes = plt.subplots(2, 3, figsize=(8, 5)) +fig = plt.figure(figsize=(8, 5)) +axes = np.zeros((2, 3), dtype=np.object) +axes[0,0] = plt.subplot(2, 3, 1, adjustable='box-forced') +axes[0,1] = plt.subplot(2, 3, 2, sharex=axes[0,0], sharey=axes[0,0], adjustable='box-forced') +axes[0,2] = plt.subplot(2, 3, 3, sharex=axes[0,0], sharey=axes[0,0], adjustable='box-forced') +axes[1,0] = plt.subplot(2, 3, 4) +axes[1,1] = plt.subplot(2, 3, 5) +axes[1,2] = plt.subplot(2, 3, 6) ax_img, ax_hist, ax_cdf = plot_img_and_hist(img, axes[:, 0]) ax_img.set_title('Low contrast image') diff --git a/doc/examples/plot_local_otsu.py b/doc/examples/plot_local_otsu.py index 210d5c03..d853c25a 100644 --- a/doc/examples/plot_local_otsu.py +++ b/doc/examples/plot_local_otsu.py @@ -37,7 +37,7 @@ threshold_global_otsu = threshold_otsu(img) global_otsu = img >= threshold_global_otsu -fig, ax = plt.subplots(2, 2, figsize=(8, 5)) +fig, ax = plt.subplots(2, 2, figsize=(8, 5), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax1, ax2, ax3, ax4 = ax.ravel() fig.colorbar(ax1.imshow(img, cmap=plt.cm.gray), diff --git a/doc/examples/plot_log_gamma.py b/doc/examples/plot_log_gamma.py index 04a1edbb..70d5881c 100644 --- a/doc/examples/plot_log_gamma.py +++ b/doc/examples/plot_log_gamma.py @@ -54,7 +54,14 @@ gamma_corrected = exposure.adjust_gamma(img, 2) logarithmic_corrected = exposure.adjust_log(img, 1) # Display results -fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(8, 5)) +fig = plt.figure(figsize=(8, 5)) +axes = np.zeros((2,3), dtype=np.object) +axes[0, 0] = plt.subplot(2, 3, 1, adjustable='box-forced') +axes[0, 1] = plt.subplot(2, 3, 2, sharex=axes[0, 0], sharey=axes[0, 0], adjustable='box-forced') +axes[0, 2] = plt.subplot(2, 3, 3, sharex=axes[0, 0], sharey=axes[0, 0], adjustable='box-forced') +axes[1, 0] = plt.subplot(2, 3, 4) +axes[1, 1] = plt.subplot(2, 3, 5) +axes[1, 2] = plt.subplot(2, 3, 6) ax_img, ax_hist, ax_cdf = plot_img_and_hist(img, axes[:, 0]) ax_img.set_title('Low contrast image') diff --git a/doc/examples/plot_marked_watershed.py b/doc/examples/plot_marked_watershed.py index 8180f982..3365740c 100644 --- a/doc/examples/plot_marked_watershed.py +++ b/doc/examples/plot_marked_watershed.py @@ -45,7 +45,8 @@ gradient = rank.gradient(denoised, disk(2)) labels = watershed(gradient, markers) # display results -fig, axes = plt.subplots(ncols=4, figsize=(8, 2.7)) +fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(8, 8), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) +axes = axes.ravel() ax0, ax1, ax2, ax3 = axes ax0.imshow(image, cmap=plt.cm.gray, interpolation='nearest') @@ -61,6 +62,5 @@ ax3.set_title("Segmented") for ax in axes: ax.axis('off') -fig.subplots_adjust(hspace=0.01, wspace=0.01, top=0.9, bottom=0, - left=0, right=1) +fig.tight_layout() plt.show() diff --git a/doc/examples/plot_medial_transform.py b/doc/examples/plot_medial_transform.py index 436e439e..8b9775cd 100644 --- a/doc/examples/plot_medial_transform.py +++ b/doc/examples/plot_medial_transform.py @@ -54,7 +54,7 @@ skel, distance = medial_axis(data, return_distance=True) # Distance to the background for pixels of the skeleton dist_on_skel = distance * skel -fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4)) +fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax1.imshow(data, cmap=plt.cm.gray, interpolation='nearest') ax1.axis('off') ax2.imshow(dist_on_skel, cmap=plt.cm.spectral, interpolation='nearest') diff --git a/doc/examples/plot_nonlocal_means.py b/doc/examples/plot_nonlocal_means.py index 207f0ca4..6082ee9c 100644 --- a/doc/examples/plot_nonlocal_means.py +++ b/doc/examples/plot_nonlocal_means.py @@ -26,7 +26,7 @@ noisy = np.clip(noisy, 0, 1) denoise = denoise_nl_means(noisy, 7, 9, 0.08) -fig, ax = plt.subplots(ncols=2, figsize=(8, 4)) +fig, ax = plt.subplots(ncols=2, figsize=(8, 4), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax[0].imshow(noisy) ax[0].axis('off') diff --git a/doc/examples/plot_otsu.py b/doc/examples/plot_otsu.py index 14a7e7cb..c279a65b 100644 --- a/doc/examples/plot_otsu.py +++ b/doc/examples/plot_otsu.py @@ -28,7 +28,12 @@ image = camera() thresh = threshold_otsu(image) binary = image > thresh -fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 2.5)) +#fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 2.5)) +fig = plt.figure(figsize=(8, 2.5)) +ax1 = plt.subplot(1, 3, 1, adjustable='box-forced') +ax2 = plt.subplot(1, 3, 2) +ax3 = plt.subplot(1, 3, 3, sharex=ax1, sharey=ax1, adjustable='box-forced') + ax1.imshow(image, cmap=plt.cm.gray) ax1.set_title('Original') ax1.axis('off') diff --git a/doc/examples/plot_peak_local_max.py b/doc/examples/plot_peak_local_max.py index aba2aab0..8a690c5e 100644 --- a/doc/examples/plot_peak_local_max.py +++ b/doc/examples/plot_peak_local_max.py @@ -25,7 +25,7 @@ image_max = ndi.maximum_filter(im, size=20, mode='constant') coordinates = peak_local_max(im, min_distance=20) # display results -fig, ax = plt.subplots(1, 3, figsize=(8, 3)) +fig, ax = plt.subplots(1, 3, figsize=(8, 3), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax1, ax2, ax3 = ax.ravel() ax1.imshow(im, cmap=plt.cm.gray) ax1.axis('off') diff --git a/doc/examples/plot_phase_unwrap.py b/doc/examples/plot_phase_unwrap.py index edb061aa..4de93dee 100644 --- a/doc/examples/plot_phase_unwrap.py +++ b/doc/examples/plot_phase_unwrap.py @@ -26,7 +26,7 @@ image_wrapped = np.angle(np.exp(1j * image)) # Perform phase unwrapping image_unwrapped = unwrap_phase(image_wrapped) -fig, ax = plt.subplots(2, 2) +fig, ax = plt.subplots(2, 2, sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax1, ax2, ax3, ax4 = ax.ravel() fig.colorbar(ax1.imshow(image, cmap='gray', vmin=0, vmax=4 * np.pi), ax=ax1) diff --git a/doc/examples/plot_radon_transform.py b/doc/examples/plot_radon_transform.py index 91775ba0..cc327d72 100644 --- a/doc/examples/plot_radon_transform.py +++ b/doc/examples/plot_radon_transform.py @@ -101,7 +101,7 @@ error = reconstruction_fbp - image print('FBP rms reconstruction error: %.3g' % np.sqrt(np.mean(error**2))) imkwargs = dict(vmin=-0.2, vmax=0.2) -fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4.5)) +fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4.5), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax1.set_title("Reconstruction\nFiltered back projection") ax1.imshow(reconstruction_fbp, cmap=plt.cm.Greys_r) ax2.set_title("Reconstruction error\nFiltered back projection") @@ -152,7 +152,7 @@ error = reconstruction_sart - image print('SART (1 iteration) rms reconstruction error: %.3g' % np.sqrt(np.mean(error**2))) -fig, ax = plt.subplots(2, 2, figsize=(8, 8.5)) +fig, ax = plt.subplots(2, 2, figsize=(8, 8.5), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax1, ax2, ax3, ax4 = ax.ravel() ax1.set_title("Reconstruction\nSART") ax1.imshow(reconstruction_sart, cmap=plt.cm.Greys_r) diff --git a/doc/examples/plot_random_walker_segmentation.py b/doc/examples/plot_random_walker_segmentation.py index 446e938f..81e0bd91 100644 --- a/doc/examples/plot_random_walker_segmentation.py +++ b/doc/examples/plot_random_walker_segmentation.py @@ -38,15 +38,18 @@ markers[data > 1.3] = 2 labels = random_walker(data, markers, beta=10, mode='bf') # Plot results -fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 3.2)) +fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 3.2), sharex=True, sharey=True) ax1.imshow(data, cmap='gray', interpolation='nearest') ax1.axis('off') +ax1.set_adjustable('box-forced') ax1.set_title('Noisy data') ax2.imshow(markers, cmap='hot', interpolation='nearest') ax2.axis('off') +ax2.set_adjustable('box-forced') ax2.set_title('Markers') ax3.imshow(labels, cmap='gray', interpolation='nearest') ax3.axis('off') +ax3.set_adjustable('box-forced') ax3.set_title('Segmentation') fig.subplots_adjust(hspace=0.01, wspace=0.01, top=1, bottom=0, left=0, diff --git a/doc/examples/plot_rank_mean.py b/doc/examples/plot_rank_mean.py index e8f2394c..51f69788 100644 --- a/doc/examples/plot_rank_mean.py +++ b/doc/examples/plot_rank_mean.py @@ -34,19 +34,16 @@ bilateral_result = rank.mean_bilateral(image, selem=selem, s0=500, s1=500) normal_result = rank.mean(image, selem=selem) -fig, axes = plt.subplots(nrows=3, figsize=(8, 10)) -ax0, ax1, ax2 = axes +fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(8, 10), sharex=True, sharey=True) +ax = axes.ravel() -ax0.imshow(np.hstack((image, percentile_result))) -ax0.set_title('Percentile mean') -ax0.axis('off') +titles = ['Original', 'Percentile mean', 'Bilateral mean', 'Local mean'] +imgs = [image, percentile_result, bilateral_result, normal_result] +for n in range(0, len(imgs)): + ax[n].imshow(imgs[n]) + ax[n].set_title(titles[n]) + ax[n].set_adjustable('box-forced') + ax[n].axis('off') -ax1.imshow(np.hstack((image, bilateral_result))) -ax1.set_title('Bilateral mean') -ax1.axis('off') - -ax2.imshow(np.hstack((image, normal_result))) -ax2.set_title('Local mean') -ax2.axis('off') plt.show() diff --git a/doc/examples/plot_regional_maxima.py b/doc/examples/plot_regional_maxima.py index dd676014..a2f9c570 100644 --- a/doc/examples/plot_regional_maxima.py +++ b/doc/examples/plot_regional_maxima.py @@ -36,19 +36,22 @@ Subtracting the dilated image leaves an image with just the coins and a flat, black background, as shown below. """ -fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(8, 2.5)) +fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 2.5), sharex=True, sharey=True) ax1.imshow(image) ax1.set_title('original image') ax1.axis('off') +ax1.set_adjustable('box-forced') ax2.imshow(dilated, vmin=image.min(), vmax=image.max()) ax2.set_title('dilated') ax2.axis('off') +ax2.set_adjustable('box-forced') ax3.imshow(image - dilated) ax3.set_title('image - dilated') ax3.axis('off') +ax3.set_adjustable('box-forced') fig.tight_layout() @@ -76,7 +79,7 @@ mask, seed, and dilated images along a slice of the image (indicated by red line). """ -fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(8, 2.5)) +fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 2.5)) yslice = 197 diff --git a/doc/examples/plot_register_translation.py b/doc/examples/plot_register_translation.py index 05cf78bf..c558e107 100644 --- a/doc/examples/plot_register_translation.py +++ b/doc/examples/plot_register_translation.py @@ -34,7 +34,10 @@ print(shift) # pixel precision first shift, error, diffphase = register_translation(image, offset_image) -fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(8, 3)) +fig = plt.figure(figsize=(8, 3)) +ax1 = plt.subplot(1, 3, 1, adjustable='box-forced') +ax2 = plt.subplot(1, 3, 2, sharex=ax1, sharey=ax1, adjustable='box-forced') +ax3 = plt.subplot(1, 3, 3) ax1.imshow(image) ax1.set_axis_off() @@ -60,7 +63,10 @@ print(shift) # subpixel precision shift, error, diffphase = register_translation(image, offset_image, 100) -fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(8, 3)) +fig = plt.figure(figsize=(8, 3)) +ax1 = plt.subplot(1, 3, 1, adjustable='box-forced') +ax2 = plt.subplot(1, 3, 2, sharex=ax1, sharey=ax1, adjustable='box-forced') +ax3 = plt.subplot(1, 3, 3) ax1.imshow(image) ax1.set_axis_off() diff --git a/doc/examples/plot_restoration.py b/doc/examples/plot_restoration.py index 52cbec27..221a53b7 100644 --- a/doc/examples/plot_restoration.py +++ b/doc/examples/plot_restoration.py @@ -42,7 +42,7 @@ astro += 0.1 * astro.std() * np.random.standard_normal(astro.shape) deconvolved, _ = restoration.unsupervised_wiener(astro, psf) -fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(8, 5)) +fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(8, 5), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) plt.gray() diff --git a/doc/examples/plot_segmentations.py b/doc/examples/plot_segmentations.py index 7f0c5752..af601f53 100644 --- a/doc/examples/plot_segmentations.py +++ b/doc/examples/plot_segmentations.py @@ -79,7 +79,7 @@ print("Felzenszwalb's number of segments: %d" % len(np.unique(segments_fz))) print("Slic number of segments: %d" % len(np.unique(segments_slic))) print("Quickshift number of segments: %d" % len(np.unique(segments_quick))) -fig, ax = plt.subplots(1, 3) +fig, ax = plt.subplots(1, 3, sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) fig.set_size_inches(8, 3, forward=True) fig.subplots_adjust(0.05, 0.05, 0.95, 0.95, 0.05, 0.05) diff --git a/doc/examples/plot_skeleton.py b/doc/examples/plot_skeleton.py index a4a3a60c..2bba3567 100644 --- a/doc/examples/plot_skeleton.py +++ b/doc/examples/plot_skeleton.py @@ -47,7 +47,7 @@ image[circle2] = 0 skeleton = skeletonize(image) # display results -fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4.5)) +fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4.5), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax1.imshow(image, cmap=plt.cm.gray) ax1.axis('off') diff --git a/doc/examples/plot_ssim.py b/doc/examples/plot_ssim.py index 1592136b..112a6971 100644 --- a/doc/examples/plot_ssim.py +++ b/doc/examples/plot_ssim.py @@ -45,7 +45,7 @@ def mse(x, y): img_noise = img + noise img_const = img + abs(noise) -fig, (ax0, ax1, ax2) = plt.subplots(nrows=1, ncols=3, figsize=(8, 4)) +fig, (ax0, ax1, ax2) = plt.subplots(nrows=1, ncols=3, figsize=(8, 4), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) mse_none = mse(img, img) ssim_none = ssim(img, img, dynamic_range=img.max() - img.min()) diff --git a/doc/examples/plot_swirl.py b/doc/examples/plot_swirl.py index 8f79db94..b93efe9f 100644 --- a/doc/examples/plot_swirl.py +++ b/doc/examples/plot_swirl.py @@ -74,7 +74,7 @@ from skimage.transform import swirl image = data.checkerboard() swirled = swirl(image, rotation=0, strength=10, radius=120, order=2) -fig, (ax0, ax1) = plt.subplots(1, 2, figsize=(8, 3)) +fig, (ax0, ax1) = plt.subplots(1, 2, figsize=(8, 3), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax0.imshow(image, cmap=plt.cm.gray, interpolation='none') ax0.axis('off') diff --git a/doc/examples/plot_template.py b/doc/examples/plot_template.py index 08581625..c7b4f01a 100644 --- a/doc/examples/plot_template.py +++ b/doc/examples/plot_template.py @@ -33,7 +33,10 @@ result = match_template(image, coin) ij = np.unravel_index(np.argmax(result), result.shape) x, y = ij[::-1] -fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(8, 3)) +fig = plt.figure(figsize=(8, 3)) +ax1 = plt.subplot(1, 3, 1) +ax2 = plt.subplot(1, 3, 2, adjustable='box-forced') +ax3 = plt.subplot(1, 3, 3, sharex=ax2, sharey=ax2, adjustable='box-forced') ax1.imshow(coin) ax1.set_axis_off() diff --git a/doc/examples/plot_tinting_grayscale_images.py b/doc/examples/plot_tinting_grayscale_images.py index 008ed065..2ba54396 100644 --- a/doc/examples/plot_tinting_grayscale_images.py +++ b/doc/examples/plot_tinting_grayscale_images.py @@ -28,9 +28,11 @@ image = color.gray2rgb(grayscale_image) red_multiplier = [1, 0, 0] yellow_multiplier = [1, 1, 0] -fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4)) +fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4), sharex=True, sharey=True) ax1.imshow(red_multiplier * image) ax2.imshow(yellow_multiplier * image) +ax1.set_adjustable('box-forced') +ax2.set_adjustable('box-forced') """ .. image:: PLOT2RST.current_figure @@ -104,13 +106,14 @@ and a non-zero saturation: hue_rotations = np.linspace(0, 1, 6) -fig, axes = plt.subplots(nrows=2, ncols=3) +fig, axes = plt.subplots(nrows=2, ncols=3, sharex=True, sharey=True) for ax, hue in zip(axes.flat, hue_rotations): # Turn down the saturation to give it that vintage look. tinted_image = colorize(image, hue, saturation=0.3) ax.imshow(tinted_image, vmin=0, vmax=1) ax.set_axis_off() + ax.set_adjustable('box-forced') fig.tight_layout() """ @@ -142,9 +145,11 @@ textured_regions = noisy > 4 masked_image = image.copy() masked_image[textured_regions, :] *= red_multiplier -fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4)) +fig, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, figsize=(8, 4), sharex=True, sharey=True) ax1.imshow(sliced_image) ax2.imshow(masked_image) +ax1.set_adjustable('box-forced') +ax2.set_adjustable('box-forced') plt.show() diff --git a/doc/examples/plot_view_as_blocks.py b/doc/examples/plot_view_as_blocks.py index eeb510ed..1a85bc41 100644 --- a/doc/examples/plot_view_as_blocks.py +++ b/doc/examples/plot_view_as_blocks.py @@ -44,21 +44,26 @@ max_view = np.max(flatten_view, axis=2) median_view = np.median(flatten_view, axis=2) # -- display resampled images -fig, axes = plt.subplots(2, 2, figsize=(8, 8)) +fig, axes = plt.subplots(2, 2, figsize=(8, 8), sharex=True, sharey=True) ax0, ax1, ax2, ax3 = axes.ravel() ax0.set_title("Original rescaled with\n spline interpolation (order=3)") l_resized = ndi.zoom(l, 2, order=3) -ax0.imshow(l_resized, cmap=cm.Greys_r) +#ax0.imshow(l_resized, cmap=cm.Greys_r) +ax0.imshow(l_resized, extent=(0, 128, 128, 0), interpolation='nearest', cmap=cm.Greys_r) +ax0.set_axis_off() ax1.set_title("Block view with\n local mean pooling") -ax1.imshow(mean_view, cmap=cm.Greys_r) +ax1.imshow(mean_view, interpolation='nearest', cmap=cm.Greys_r) +ax1.set_axis_off() ax2.set_title("Block view with\n local max pooling") -ax2.imshow(max_view, cmap=cm.Greys_r) +ax2.imshow(max_view, interpolation='nearest', cmap=cm.Greys_r) +ax2.set_axis_off() ax3.set_title("Block view with\n local median pooling") -ax3.imshow(median_view, cmap=cm.Greys_r) +ax3.imshow(median_view, interpolation='nearest', cmap=cm.Greys_r) +ax3.set_axis_off() fig.subplots_adjust(hspace=0.4, wspace=0.4) plt.show() diff --git a/doc/examples/plot_watershed.py b/doc/examples/plot_watershed.py index 5d65238f..664c4c77 100644 --- a/doc/examples/plot_watershed.py +++ b/doc/examples/plot_watershed.py @@ -48,7 +48,7 @@ local_maxi = peak_local_max(distance, indices=False, footprint=np.ones((3, 3)), markers = ndi.label(local_maxi)[0] labels = watershed(-distance, markers, mask=image) -fig, axes = plt.subplots(ncols=3, figsize=(8, 2.7)) +fig, axes = plt.subplots(ncols=3, figsize=(8, 2.7), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax0, ax1, ax2 = axes ax0.imshow(image, cmap=plt.cm.gray, interpolation='nearest')