mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-08 10:23:17 +08:00
adding shared axes to examples with multiple plots
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user