From 681be3fc58adb9450163789d236271eeda3f67ab Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 7 Sep 2015 18:13:00 +0200 Subject: [PATCH 01/13] adding shared axes to examples with multiple plots --- .../applications/plot_coins_segmentation.py | 5 +- doc/examples/applications/plot_morphology.py | 2 +- .../applications/plot_rank_filters.py | 59 ++++++++++++++----- doc/examples/plot_canny.py | 2 +- doc/examples/plot_denoise.py | 2 +- doc/examples/plot_edge_filter.py | 4 +- doc/examples/plot_equalize.py | 8 ++- doc/examples/plot_hog.py | 2 +- doc/examples/plot_line_hough_transform.py | 16 ++--- doc/examples/plot_local_otsu.py | 2 +- .../plot_random_walker_segmentation.py | 2 +- doc/examples/plot_tinting_grayscale_images.py | 9 ++- doc/examples/plot_view_as_blocks.py | 15 +++-- doc/examples/plot_watershed.py | 2 +- 14 files changed, 89 insertions(+), 41 deletions(-) diff --git a/doc/examples/applications/plot_coins_segmentation.py b/doc/examples/applications/plot_coins_segmentation.py index fe165760..78df6883 100644 --- a/doc/examples/applications/plot_coins_segmentation.py +++ b/doc/examples/applications/plot_coins_segmentation.py @@ -35,7 +35,7 @@ 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') @@ -162,7 +162,8 @@ 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)) +# TODO: this example would benefit from sharing axes over multiple figures +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') diff --git a/doc/examples/applications/plot_morphology.py b/doc/examples/applications/plot_morphology.py index 68ecc6d6..b2f9b323 100644 --- a/doc/examples/applications/plot_morphology.py +++ b/doc/examples/applications/plot_morphology.py @@ -42,7 +42,7 @@ 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') diff --git a/doc/examples/applications/plot_rank_filters.py b/doc/examples/applications/plot_rank_filters.py index e2dbd71b..41b89769 100644 --- a/doc/examples/applications/plot_rank_filters.py +++ b/doc/examples/applications/plot_rank_filters.py @@ -70,7 +70,7 @@ 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) @@ -109,7 +109,7 @@ 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)) @@ -143,7 +143,7 @@ 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) @@ -196,7 +196,8 @@ hist = np.histogram(noisy_image, bins=np.arange(0, 256)) glob_hist = np.histogram(glob, bins=np.arange(0, 256)) loc_hist = np.histogram(loc, bins=np.arange(0, 256)) -fig, ax = plt.subplots(3, 2, figsize=(10, 10)) +# this way histograms also share the axes +fig, ax = plt.subplots(3, 2, figsize=(10, 10), sharex='col', sharey='col') ax1, ax2, ax3, ax4, ax5, ax6 = ax.ravel() ax1.imshow(noisy_image, interpolation='nearest', cmap=plt.cm.gray) @@ -236,7 +237,7 @@ 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') @@ -271,13 +272,33 @@ 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') +#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() + +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') + +''' ax1.imshow( np.hstack((loc_perc_autolevel0, loc_perc_autolevel1)), vmin=0, vmax=255) ax1.set_title('Percentile auto-level 0%,1%') @@ -287,6 +308,7 @@ ax2.set_title('Percentile auto-level 5% and 10%') for ax in axes: ax.axis('off') +''' """ @@ -304,7 +326,7 @@ 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) @@ -336,7 +358,7 @@ 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) @@ -393,7 +415,7 @@ 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) @@ -429,7 +451,7 @@ 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') @@ -468,7 +490,7 @@ 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) @@ -518,7 +540,7 @@ 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') @@ -680,10 +702,19 @@ 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') +ax1.set_title('scipy.ndimage.percentile') +ax1.imshow(rndi) +ax1.axis('off') """ .. image:: PLOT2RST.current_figure 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_denoise.py b/doc/examples/plot_denoise.py index 1313bc04..35d05e08 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) plt.gray() diff --git a/doc/examples/plot_edge_filter.py b/doc/examples/plot_edge_filter.py index 96b654a8..b3c26c07 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) 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) ax0.imshow(img, cmap=plt.cm.gray) ax0.set_title('Original image') diff --git a/doc/examples/plot_equalize.py b/doc/examples/plot_equalize.py index 2d04e22a..82bd4eaf 100644 --- a/doc/examples/plot_equalize.py +++ b/doc/examples/plot_equalize.py @@ -70,7 +70,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..d181eea7 100644 --- a/doc/examples/plot_hog.py +++ b/doc/examples/plot_hog.py @@ -90,7 +90,7 @@ 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) diff --git a/doc/examples/plot_line_hough_transform.py b/doc/examples/plot_line_hough_transform.py index 7ee3f1f7..9d508385 100644 --- a/doc/examples/plot_line_hough_transform.py +++ b/doc/examples/plot_line_hough_transform.py @@ -77,11 +77,13 @@ image[idx, idx] = 255 h, theta, d = hough_line(image) -fig, ax = plt.subplots(1, 3, figsize=(8, 4)) +fig, ax = plt.subplots(1, 3, figsize=(8, 4), sharex=True, sharey=True) +fig.delaxes(ax[1]) +ax[1] = fig.add_subplot(1, 3, 2) ax[0].imshow(image, cmap=plt.cm.gray) ax[0].set_title('Input image') -ax[0].axis('image') +ax[0].set_axis_off() ax[1].imshow(np.log(1 + h), extent=[np.rad2deg(theta[-1]), np.rad2deg(theta[0]), @@ -100,7 +102,7 @@ for _, angle, dist in zip(*hough_line_peaks(h, theta, d)): 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') +ax[2].set_axis_off() # Line finding, using the Probabilistic Hough Transform @@ -109,15 +111,15 @@ 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)) +fig2, ax = plt.subplots(1, 3, figsize=(8, 3), sharex=True, sharey=True) ax[0].imshow(image, cmap=plt.cm.gray) ax[0].set_title('Input image') -ax[0].axis('image') +ax[0].set_axis_off() ax[1].imshow(edges, cmap=plt.cm.gray) ax[1].set_title('Canny edges') -ax[1].axis('image') +ax[1].set_axis_off() ax[2].imshow(edges * 0) @@ -126,5 +128,5 @@ for line in lines: ax[2].plot((p0[0], p1[0]), (p0[1], p1[1])) ax[2].set_title('Probabilistic Hough') -ax[2].axis('image') +ax[2].set_axis_off() plt.show() diff --git a/doc/examples/plot_local_otsu.py b/doc/examples/plot_local_otsu.py index 210d5c03..6c5dca17 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) ax1, ax2, ax3, ax4 = ax.ravel() fig.colorbar(ax1.imshow(img, cmap=plt.cm.gray), diff --git a/doc/examples/plot_random_walker_segmentation.py b/doc/examples/plot_random_walker_segmentation.py index 446e938f..0d8ed924 100644 --- a/doc/examples/plot_random_walker_segmentation.py +++ b/doc/examples/plot_random_walker_segmentation.py @@ -38,7 +38,7 @@ 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_title('Noisy data') diff --git a/doc/examples/plot_tinting_grayscale_images.py b/doc/examples/plot_tinting_grayscale_images.py index 008ed065..e0c1cb32 100644 --- a/doc/examples/plot_tinting_grayscale_images.py +++ b/doc/examples/plot_tinting_grayscale_images.py @@ -28,7 +28,10 @@ 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)) +# sharing the axes makes the grid show beneath the image +# this could be solved by calling set_axis_off() where this +# behaviour is not wanted +fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4), sharex=True, sharey=True) ax1.imshow(red_multiplier * image) ax2.imshow(yellow_multiplier * image) @@ -104,7 +107,7 @@ 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. @@ -142,7 +145,7 @@ 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) 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..de2fa67e 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) ax0, ax1, ax2 = axes ax0.imshow(image, cmap=plt.cm.gray, interpolation='nearest') From 8ff6d2d8e37515364b883b79d1a9da563b84c2c5 Mon Sep 17 00:00:00 2001 From: martin Date: Tue, 8 Sep 2015 18:02:42 +0200 Subject: [PATCH 02/13] changed adjustable parameter of axes to 'box-forced' this fixes the size of axes around an image for shared axes --- .../applications/plot_coins_segmentation.py | 9 ++- doc/examples/applications/plot_morphology.py | 2 + .../applications/plot_rank_filters.py | 55 ++++++------------ doc/examples/plot_edge_filter.py | 4 +- doc/examples/plot_equalize.py | 1 + doc/examples/plot_hog.py | 2 + doc/examples/plot_line_hough_transform.py | 58 ++++++++++--------- doc/examples/plot_local_otsu.py | 2 +- .../plot_random_walker_segmentation.py | 5 +- doc/examples/plot_tinting_grayscale_images.py | 8 ++- doc/examples/plot_watershed.py | 2 +- 11 files changed, 74 insertions(+), 74 deletions(-) diff --git a/doc/examples/applications/plot_coins_segmentation.py b/doc/examples/applications/plot_coins_segmentation.py index 78df6883..29cacac9 100644 --- a/doc/examples/applications/plot_coins_segmentation.py +++ b/doc/examples/applications/plot_coins_segmentation.py @@ -35,7 +35,9 @@ background with the coins: """ -fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3), sharex=True, sharey=True) +fig = plt.figure(figsize=(6,3)) +ax1 = fig.add_subplot(1, 2, 1, adjustable='box-forced') +ax2 = fig.add_subplot(1, 2, 2, sharex = ax1, sharey = ax1, adjustable='box-forced') ax1.imshow(coins > 100, cmap=plt.cm.gray, interpolation='nearest') ax1.set_title('coins > 100') ax1.axis('off') @@ -162,8 +164,9 @@ segmentation = ndi.binary_fill_holes(segmentation - 1) labeled_coins, _ = ndi.label(segmentation) image_label_overlay = label2rgb(labeled_coins, image=coins) -# TODO: this example would benefit from sharing axes over multiple figures -fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3), sharex=True, sharey=True) +fig = plt.figure(figsize=(6,3)) +ax1 = fig.add_subplot(1, 2, 1, adjustable='box-forced') +ax2 = fig.add_subplot(1, 2, 2, sharex = ax1, sharey = ax1, adjustable='box-forced') ax1.imshow(coins, cmap=plt.cm.gray, interpolation='nearest') ax1.contour(segmentation, [0.5], linewidths=1.2, colors='y') ax1.axis('off') diff --git a/doc/examples/applications/plot_morphology.py b/doc/examples/applications/plot_morphology.py index b2f9b323..33246793 100644 --- a/doc/examples/applications/plot_morphology.py +++ b/doc/examples/applications/plot_morphology.py @@ -46,9 +46,11 @@ def plot_comparison(original, filtered, filter_name): 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 41b89769..13620ebf 100644 --- a/doc/examples/applications/plot_rank_filters.py +++ b/doc/examples/applications/plot_rank_filters.py @@ -70,7 +70,7 @@ 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), sharex=True, sharey=True) +fig, ax = plt.subplots(2, 2, figsize=(10, 7), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax1, ax2, ax3, ax4 = ax.ravel() ax1.imshow(noisy_image, vmin=0, vmax=255, cmap=plt.cm.gray) @@ -109,7 +109,7 @@ image. from skimage.filters.rank import mean -fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[10, 7], sharex=True, sharey=True) +fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[10, 7], sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) loc_mean = mean(noisy_image, disk(10)) @@ -143,7 +143,7 @@ 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), sharex='row', sharey='row') +fig, ax = plt.subplots(2, 2, figsize=(10, 7), sharex='row', sharey='row', subplot_kw={'adjustable':'box-forced'}) ax1, ax2, ax3, ax4 = ax.ravel() ax1.imshow(noisy_image, cmap=plt.cm.gray) @@ -196,9 +196,13 @@ hist = np.histogram(noisy_image, bins=np.arange(0, 256)) glob_hist = np.histogram(glob, bins=np.arange(0, 256)) loc_hist = np.histogram(loc, bins=np.arange(0, 256)) -# this way histograms also share the axes -fig, ax = plt.subplots(3, 2, figsize=(10, 10), sharex='col', sharey='col') -ax1, ax2, ax3, ax4, ax5, ax6 = ax.ravel() +fig = plt.figure() +ax1 = plt.subplot(3, 2, 1, adjustable='box-forced') +ax2 = plt.subplot(3, 2, 2) +ax3 = plt.subplot(3, 2, 3, adjustable='box-forced', sharex=ax1, sharey=ax1) +ax4 = plt.subplot(3, 2, 4) +ax5 = plt.subplot(3, 2, 5, adjustable='box-forced', sharex=ax1, sharey=ax1) +ax6 = plt.subplot(3, 2, 6) ax1.imshow(noisy_image, interpolation='nearest', cmap=plt.cm.gray) ax1.axis('off') @@ -237,7 +241,7 @@ 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], sharex=True, sharey=True) +fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[10, 7], sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax1.imshow(noisy_image, cmap=plt.cm.gray) ax1.set_title('Original') @@ -272,13 +276,10 @@ 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, ncols=2, figsize=(7, 8), sharex=True, sharey=True) +fig, axes = plt.subplots(nrows=3, ncols=2, figsize=(7, 8), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) 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%', @@ -298,18 +299,6 @@ for i in range(0,len(image_list)): axes_list[i].set_title(title_list[i]) axes_list[i].axis('off') -''' -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') -''' - """ .. image:: PLOT2RST.current_figure @@ -326,7 +315,7 @@ noisy_image = img_as_ubyte(data.camera()) enh = enhance_contrast(noisy_image, disk(5)) -fig, ax = plt.subplots(2, 2, figsize=[10, 7], sharex='row', sharey='row') +fig, ax = plt.subplots(2, 2, figsize=[10, 7], sharex='row', sharey='row', subplot_kw={'adjustable':'box-forced'}) ax1, ax2, ax3, ax4 = ax.ravel() ax1.imshow(noisy_image, cmap=plt.cm.gray) @@ -358,7 +347,7 @@ 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], sharex='row', sharey='row') +fig, ax = plt.subplots(2, 2, figsize=[10, 7], sharex='row', sharey='row', subplot_kw={'adjustable':'box-forced'}) ax1, ax2, ax3, ax4 = ax.ravel() ax1.imshow(noisy_image, cmap=plt.cm.gray) @@ -415,7 +404,7 @@ loc_otsu = p8 >= t_loc_otsu t_glob_otsu = threshold_otsu(p8) glob_otsu = p8 >= t_glob_otsu -fig, ax = plt.subplots(2, 2, sharex=True, sharey=True) +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(p8, cmap=plt.cm.gray), ax=ax1) @@ -451,7 +440,7 @@ 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, sharex=True, sharey=True) +fig, (ax1, ax2) = plt.subplots(1, 2, sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax1.imshow(m) ax1.set_title('Original') @@ -490,7 +479,7 @@ 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], sharex=True, sharey=True) +fig, ax = plt.subplots(2, 2, figsize=[10, 7], sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax1, ax2, ax3, ax4 = ax.ravel() ax1.imshow(noisy_image, cmap=plt.cm.gray) @@ -540,7 +529,7 @@ import matplotlib.pyplot as plt image = data.camera() -fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4), sharex=True, sharey=True) +fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) fig.colorbar(ax1.imshow(image, cmap=plt.cm.gray), ax=ax1) ax1.set_title('Image') @@ -702,13 +691,7 @@ 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) +fig, (ax0, ax1) = plt.subplots(ncols=2, sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) ax0.set_title('filters.rank.median') ax0.imshow(rc) ax0.axis('off') diff --git a/doc/examples/plot_edge_filter.py b/doc/examples/plot_edge_filter.py index b3c26c07..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, sharex=True, sharey=True) +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, sharex=True, sharey=True) +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_equalize.py b/doc/examples/plot_equalize.py index 82bd4eaf..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') diff --git a/doc/examples/plot_hog.py b/doc/examples/plot_hog.py index d181eea7..ab71bb36 100644 --- a/doc/examples/plot_hog.py +++ b/doc/examples/plot_hog.py @@ -95,6 +95,7 @@ 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_line_hough_transform.py b/doc/examples/plot_line_hough_transform.py index 9d508385..2a5e96d7 100644 --- a/doc/examples/plot_line_hough_transform.py +++ b/doc/examples/plot_line_hough_transform.py @@ -77,32 +77,33 @@ image[idx, idx] = 255 h, theta, d = hough_line(image) -fig, ax = plt.subplots(1, 3, figsize=(8, 4), sharex=True, sharey=True) -fig.delaxes(ax[1]) -ax[1] = fig.add_subplot(1, 3, 2) +fig = plt.figure(figsize=(8, 4)) +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') -ax[0].imshow(image, cmap=plt.cm.gray) -ax[0].set_title('Input image') -ax[0].set_axis_off() +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].set_axis_off() + 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 @@ -111,22 +112,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), sharex=True, sharey=True) +fig2 = 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, sharex=ax1, sharey=ax1, adjustable='box-forced') -ax[0].imshow(image, cmap=plt.cm.gray) -ax[0].set_title('Input image') -ax[0].set_axis_off() +ax1.imshow(image, cmap=plt.cm.gray) +ax1.set_title('Input image') +ax1.set_axis_off() -ax[1].imshow(edges, cmap=plt.cm.gray) -ax[1].set_title('Canny edges') -ax[1].set_axis_off() +ax2.imshow(edges, cmap=plt.cm.gray) +ax2.set_title('Canny edges') +ax2.set_axis_off() -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].set_axis_off() +ax3.set_title('Probabilistic Hough') +ax3.set_axis_off() plt.show() diff --git a/doc/examples/plot_local_otsu.py b/doc/examples/plot_local_otsu.py index 6c5dca17..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), sharex=True, sharey=True) +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_random_walker_segmentation.py b/doc/examples/plot_random_walker_segmentation.py index 0d8ed924..8413a5a6 100644 --- a/doc/examples/plot_random_walker_segmentation.py +++ b/doc/examples/plot_random_walker_segmentation.py @@ -38,13 +38,16 @@ 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), sharex=True, sharey=True) +fig = plt.figure(figsize=(8, 3.2)) +ax1 = plt.subplot(1, 3, 1, adjustable='box-forced') ax1.imshow(data, cmap='gray', interpolation='nearest') ax1.axis('off') ax1.set_title('Noisy data') +ax2 = plt.subplot(1, 3, 2, sharex=ax1, sharey=ax1, adjustable='box-forced') ax2.imshow(markers, cmap='hot', interpolation='nearest') ax2.axis('off') ax2.set_title('Markers') +ax3 = plt.subplot(1, 3, 3, sharex=ax1, sharey=ax1, adjustable='box-forced') ax3.imshow(labels, cmap='gray', interpolation='nearest') ax3.axis('off') ax3.set_title('Segmentation') diff --git a/doc/examples/plot_tinting_grayscale_images.py b/doc/examples/plot_tinting_grayscale_images.py index e0c1cb32..2ba54396 100644 --- a/doc/examples/plot_tinting_grayscale_images.py +++ b/doc/examples/plot_tinting_grayscale_images.py @@ -28,12 +28,11 @@ image = color.gray2rgb(grayscale_image) red_multiplier = [1, 0, 0] yellow_multiplier = [1, 1, 0] -# sharing the axes makes the grid show beneath the image -# this could be solved by calling set_axis_off() where this -# behaviour is not wanted 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 @@ -114,6 +113,7 @@ for ax, hue in zip(axes.flat, hue_rotations): 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() """ @@ -148,6 +148,8 @@ masked_image[textured_regions, :] *= red_multiplier 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_watershed.py b/doc/examples/plot_watershed.py index de2fa67e..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), sharex=True, sharey=True) +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') From 9fa9c0387c0dc97bc05862efb3973f1dd14e6375 Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 11 Sep 2015 09:45:34 +0200 Subject: [PATCH 03/13] adding axes sharing to displays of related images for better interaction sharing achieved by setting sharex and sharey, and setting the axes 'adjustable' parameter to 'box-forced' --- doc/examples/plot_adapt_rgb.py | 6 ++-- doc/examples/plot_blob.py | 6 +++- ...lot_circular_elliptical_hough_transform.py | 2 +- doc/examples/plot_denoise.py | 2 +- doc/examples/plot_entropy.py | 2 +- doc/examples/plot_gabor.py | 14 +++++++++- doc/examples/plot_holes_and_peaks.py | 28 ++++++++++--------- doc/examples/plot_ihc_color_separation.py | 6 ++-- doc/examples/plot_join_segmentations.py | 2 +- doc/examples/plot_local_equalize.py | 9 +++++- doc/examples/plot_log_gamma.py | 9 +++++- doc/examples/plot_marked_watershed.py | 6 ++-- doc/examples/plot_medial_transform.py | 2 +- doc/examples/plot_nonlocal_means.py | 2 +- doc/examples/plot_otsu.py | 7 ++++- doc/examples/plot_peak_local_max.py | 2 +- doc/examples/plot_phase_unwrap.py | 2 +- doc/examples/plot_rank_mean.py | 21 ++++++-------- doc/examples/plot_regional_maxima.py | 10 +++++-- doc/examples/plot_register_translation.py | 10 +++++-- doc/examples/plot_restoration.py | 2 +- doc/examples/plot_skeleton.py | 2 +- doc/examples/plot_swirl.py | 2 +- doc/examples/plot_template.py | 5 +++- 24 files changed, 105 insertions(+), 54 deletions(-) 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_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 35d05e08..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), sharex=True, sharey=True) +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_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_gabor.py b/doc/examples/plot_gabor.py index 0ecc8468..fce7aff7 100644 --- a/doc/examples/plot_gabor.py +++ b/doc/examples/plot_gabor.py @@ -100,7 +100,19 @@ for theta in (0, 1): # Save kernel and the power image for each image results.append((kernel, [power(img, kernel) for img in images])) -fig, axes = plt.subplots(nrows=5, ncols=4, figsize=(5, 6)) +# Prepare exes for ploting +fig = plt.figure(figsize=(5, 6)) +axes = np.zeros((5, 4), dtype=np.object) +# first column +for n in range(0, 5): + axes[n,0] = plt.subplot(5, 4, 1+n*4) +# the other columns, each column axes are shared +for m in range(1, 4): + axes[0,m] = plt.subplot(5, 4, 1+m, adjustable='box-forced') + for n in range(1, 5): + axes[n,m] = plt.subplot(5, 4, 1+n*4+m, sharex=axes[0,m], sharey=axes[0,m]) + axes[n,m].set_adjustable('box-forced') + plt.gray() fig.suptitle('Image responses for Gabor filter kernels', fontsize=12) 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_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_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_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..cc65d2e5 100644 --- a/doc/examples/plot_regional_maxima.py +++ b/doc/examples/plot_regional_maxima.py @@ -36,7 +36,10 @@ 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 = plt.figure(figsize=(8, 2.5)) +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, sharex=ax1, sharey=ax1, adjustable='box-forced') ax1.imshow(image) ax1.set_title('original image') @@ -76,7 +79,10 @@ 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 = plt.figure(figsize=(8, 2.5)) +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') 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_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_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() From bb081ebd0ae9281f870834dedd32efc23b8f09ce Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 11 Sep 2015 09:50:49 +0200 Subject: [PATCH 04/13] added sharex, sharey and adjustable parameters to subplots --- doc/examples/plot_radon_transform.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) From ada92ae75e9278a97b85a2c1fe979687bbc39fa4 Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 11 Sep 2015 09:54:16 +0200 Subject: [PATCH 05/13] replaced subplots with individual subplot calls share axes for the related images in subplost 221 and 223 --- doc/examples/plot_gabors_from_astronaut.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/examples/plot_gabors_from_astronaut.py b/doc/examples/plot_gabors_from_astronaut.py index ed429203..095af98f 100644 --- a/doc/examples/plot_gabors_from_astronaut.py +++ b/doc/examples/plot_gabors_from_astronaut.py @@ -69,8 +69,12 @@ fb2 = fb2.reshape((-1,) + patch_shape) fb2_montage = montage2d(fb2, rescale_intensity=True) # -- -fig, axes = plt.subplots(2, 2, figsize=(7, 6)) -ax0, ax1, ax2, ax3 = axes.ravel() +fig = plt.figure(figsize=(7, 6)) +ax0 = plt.subplot(2, 2, 1, adjustable='box-forced') +ax1 = plt.subplot(2, 2, 2) +ax2 = plt.subplot(2, 2, 3, sharex=ax0, sharey=ax0, adjustable='box-forced') +ax3 = plt.subplot(2, 2, 4) + ax0.imshow(astro, cmap=plt.cm.gray) ax0.set_title("Image (original)") @@ -84,7 +88,7 @@ ax2.set_title("Image (LGN-like DoG)") ax3.imshow(fb2_montage, cmap=plt.cm.gray, interpolation='nearest') ax3.set_title("K-means filterbank (codebook)\non LGN-like DoG image") -for ax in axes.ravel(): +for ax in [ax0, ax1, ax2, ax3]: ax.axis('off') fig.subplots_adjust(hspace=0.3) From e7f5dff2151746ba7a5f419b13bc8fa852d0ebfb Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 11 Sep 2015 09:57:17 +0200 Subject: [PATCH 06/13] added parameters for axes sharing to plt.subplots --- doc/examples/plot_segmentations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From c65b095ec756150fbe9f658ad5b368700b2b880c Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 11 Sep 2015 09:58:12 +0200 Subject: [PATCH 07/13] added parameters for axes sharing to plt.subplots --- doc/examples/plot_ssim.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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()) From d42b06e69ec7de74665cc85440fa411f12959ef6 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 12 Oct 2015 16:15:39 +0200 Subject: [PATCH 08/13] changed subplot creation to preferred matplotlib style --- doc/examples/applications/plot_coins_segmentation.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/examples/applications/plot_coins_segmentation.py b/doc/examples/applications/plot_coins_segmentation.py index 29cacac9..404c1b98 100644 --- a/doc/examples/applications/plot_coins_segmentation.py +++ b/doc/examples/applications/plot_coins_segmentation.py @@ -35,15 +35,15 @@ background with the coins: """ -fig = plt.figure(figsize=(6,3)) -ax1 = fig.add_subplot(1, 2, 1, adjustable='box-forced') -ax2 = fig.add_subplot(1, 2, 2, sharex = ax1, sharey = ax1, adjustable='box-forced') +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) @@ -164,14 +164,14 @@ segmentation = ndi.binary_fill_holes(segmentation - 1) labeled_coins, _ = ndi.label(segmentation) image_label_overlay = label2rgb(labeled_coins, image=coins) -fig = plt.figure(figsize=(6,3)) -ax1 = fig.add_subplot(1, 2, 1, adjustable='box-forced') -ax2 = fig.add_subplot(1, 2, 2, sharex = ax1, sharey = ax1, adjustable='box-forced') +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) From 0ffa83113a5e1617903724ce1a5086ecac1d374e Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 12 Oct 2015 17:38:08 +0200 Subject: [PATCH 09/13] changed subplot creation to preferred matplotlib style --- .../applications/plot_rank_filters.py | 82 ++++++++++++------- 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/doc/examples/applications/plot_rank_filters.py b/doc/examples/applications/plot_rank_filters.py index 13620ebf..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), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) +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], sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) +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), sharex='row', sharey='row', subplot_kw={'adjustable':'box-forced'}) +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') """ @@ -196,13 +209,8 @@ hist = np.histogram(noisy_image, bins=np.arange(0, 256)) glob_hist = np.histogram(glob, bins=np.arange(0, 256)) loc_hist = np.histogram(loc, bins=np.arange(0, 256)) -fig = plt.figure() -ax1 = plt.subplot(3, 2, 1, adjustable='box-forced') -ax2 = plt.subplot(3, 2, 2) -ax3 = plt.subplot(3, 2, 3, adjustable='box-forced', sharex=ax1, sharey=ax1) -ax4 = plt.subplot(3, 2, 4) -ax5 = plt.subplot(3, 2, 5, adjustable='box-forced', sharex=ax1, sharey=ax1) -ax6 = plt.subplot(3, 2, 6) +fig, ax = plt.subplots(3, 2, figsize=(10, 10)) +ax1, ax2, ax3, ax4, ax5, ax6 = ax.ravel() ax1.imshow(noisy_image, interpolation='nearest', cmap=plt.cm.gray) ax1.axis('off') @@ -241,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], sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) +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') """ @@ -276,7 +286,7 @@ 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, ncols=2, figsize=(7, 8), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) +fig, axes = plt.subplots(nrows=3, ncols=2, figsize=(7, 8), sharex=True, sharey=True) ax0, ax1, ax2 = axes plt.gray() @@ -298,6 +308,7 @@ 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') """ @@ -315,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], sharex='row', sharey='row', subplot_kw={'adjustable':'box-forced'}) +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') """ @@ -347,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], sharex='row', sharey='row', subplot_kw={'adjustable':'box-forced'}) +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') """ @@ -404,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, sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) +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') """ @@ -440,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, sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) +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') """ @@ -479,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], sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) +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 @@ -529,15 +545,17 @@ import matplotlib.pyplot as plt image = data.camera() -fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) +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') """ @@ -691,13 +709,15 @@ Comparison of outcome of the three methods: """ -fig, (ax0, ax1) = plt.subplots(ncols=2, sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'}) +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 From f8e632c6b161c67f5da7b70aea6d9b9cb509bdc7 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 12 Oct 2015 17:44:02 +0200 Subject: [PATCH 10/13] changed subplot creation to preferred matplotlib style --- doc/examples/plot_random_walker_segmentation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/examples/plot_random_walker_segmentation.py b/doc/examples/plot_random_walker_segmentation.py index 8413a5a6..81e0bd91 100644 --- a/doc/examples/plot_random_walker_segmentation.py +++ b/doc/examples/plot_random_walker_segmentation.py @@ -38,18 +38,18 @@ markers[data > 1.3] = 2 labels = random_walker(data, markers, beta=10, mode='bf') # Plot results -fig = plt.figure(figsize=(8, 3.2)) -ax1 = plt.subplot(1, 3, 1, adjustable='box-forced') +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 = plt.subplot(1, 3, 2, sharex=ax1, sharey=ax1, adjustable='box-forced') ax2.imshow(markers, cmap='hot', interpolation='nearest') ax2.axis('off') +ax2.set_adjustable('box-forced') ax2.set_title('Markers') -ax3 = plt.subplot(1, 3, 3, sharex=ax1, sharey=ax1, adjustable='box-forced') 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, From 629d6d6abc2687eb2e57caf1df146955b9a649d1 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 12 Oct 2015 17:48:30 +0200 Subject: [PATCH 11/13] changed subplot creation to preferred matplotlib style --- doc/examples/plot_line_hough_transform.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/doc/examples/plot_line_hough_transform.py b/doc/examples/plot_line_hough_transform.py index 2a5e96d7..15464768 100644 --- a/doc/examples/plot_line_hough_transform.py +++ b/doc/examples/plot_line_hough_transform.py @@ -77,10 +77,7 @@ image[idx, idx] = 255 h, theta, d = hough_line(image) -fig = plt.figure(figsize=(8, 4)) -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') +fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8,4)) ax1.imshow(image, cmap=plt.cm.gray) ax1.set_title('Input image') @@ -112,18 +109,17 @@ edges = canny(image, 2, 1, 25) lines = probabilistic_hough_line(edges, threshold=10, line_length=5, line_gap=3) -fig2 = 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, sharex=ax1, sharey=ax1, adjustable='box-forced') +fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8,4), sharex=True, sharey=True) ax1.imshow(image, cmap=plt.cm.gray) ax1.set_title('Input image') ax1.set_axis_off() +ax1.set_adjustable('box-forced') ax2.imshow(edges, cmap=plt.cm.gray) ax2.set_title('Canny edges') ax2.set_axis_off() +ax2.set_adjustable('box-forced') ax3.imshow(edges * 0) @@ -133,4 +129,5 @@ for line in lines: ax3.set_title('Probabilistic Hough') ax3.set_axis_off() +ax3.set_adjustable('box-forced') plt.show() From be39c3532596e85a1e94967d81637056d32c1271 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 12 Oct 2015 17:52:43 +0200 Subject: [PATCH 12/13] changed subplot creation to preferred matplotlib style --- doc/examples/plot_regional_maxima.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/doc/examples/plot_regional_maxima.py b/doc/examples/plot_regional_maxima.py index cc65d2e5..a2f9c570 100644 --- a/doc/examples/plot_regional_maxima.py +++ b/doc/examples/plot_regional_maxima.py @@ -36,22 +36,22 @@ Subtracting the dilated image leaves an image with just the coins and a flat, black background, as shown below. """ -fig = plt.figure(figsize=(8, 2.5)) -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, sharex=ax1, sharey=ax1, adjustable='box-forced') +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() @@ -79,10 +79,7 @@ mask, seed, and dilated images along a slice of the image (indicated by red line). """ -fig = plt.figure(figsize=(8, 2.5)) -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') +fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 2.5)) yslice = 197 From 4e364c6087cf2a079e031319d7d6369d569e449d Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 12 Oct 2015 18:09:47 +0200 Subject: [PATCH 13/13] reverted subplot creation to preferred matplotlib style --- doc/examples/plot_gabor.py | 14 +------------- doc/examples/plot_gabors_from_astronaut.py | 10 +++------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/doc/examples/plot_gabor.py b/doc/examples/plot_gabor.py index fce7aff7..0ecc8468 100644 --- a/doc/examples/plot_gabor.py +++ b/doc/examples/plot_gabor.py @@ -100,19 +100,7 @@ for theta in (0, 1): # Save kernel and the power image for each image results.append((kernel, [power(img, kernel) for img in images])) -# Prepare exes for ploting -fig = plt.figure(figsize=(5, 6)) -axes = np.zeros((5, 4), dtype=np.object) -# first column -for n in range(0, 5): - axes[n,0] = plt.subplot(5, 4, 1+n*4) -# the other columns, each column axes are shared -for m in range(1, 4): - axes[0,m] = plt.subplot(5, 4, 1+m, adjustable='box-forced') - for n in range(1, 5): - axes[n,m] = plt.subplot(5, 4, 1+n*4+m, sharex=axes[0,m], sharey=axes[0,m]) - axes[n,m].set_adjustable('box-forced') - +fig, axes = plt.subplots(nrows=5, ncols=4, figsize=(5, 6)) plt.gray() fig.suptitle('Image responses for Gabor filter kernels', fontsize=12) diff --git a/doc/examples/plot_gabors_from_astronaut.py b/doc/examples/plot_gabors_from_astronaut.py index 095af98f..ed429203 100644 --- a/doc/examples/plot_gabors_from_astronaut.py +++ b/doc/examples/plot_gabors_from_astronaut.py @@ -69,12 +69,8 @@ fb2 = fb2.reshape((-1,) + patch_shape) fb2_montage = montage2d(fb2, rescale_intensity=True) # -- -fig = plt.figure(figsize=(7, 6)) -ax0 = plt.subplot(2, 2, 1, adjustable='box-forced') -ax1 = plt.subplot(2, 2, 2) -ax2 = plt.subplot(2, 2, 3, sharex=ax0, sharey=ax0, adjustable='box-forced') -ax3 = plt.subplot(2, 2, 4) - +fig, axes = plt.subplots(2, 2, figsize=(7, 6)) +ax0, ax1, ax2, ax3 = axes.ravel() ax0.imshow(astro, cmap=plt.cm.gray) ax0.set_title("Image (original)") @@ -88,7 +84,7 @@ ax2.set_title("Image (LGN-like DoG)") ax3.imshow(fb2_montage, cmap=plt.cm.gray, interpolation='nearest') ax3.set_title("K-means filterbank (codebook)\non LGN-like DoG image") -for ax in [ax0, ax1, ax2, ax3]: +for ax in axes.ravel(): ax.axis('off') fig.subplots_adjust(hspace=0.3)