Skip to content

Instantly share code, notes, and snippets.

@stephengruppetta
Created November 22, 2023 23:10
Show Gist options
  • Save stephengruppetta/505b26b010b635afce26138e344b4ab9 to your computer and use it in GitHub Desktop.
Save stephengruppetta/505b26b010b635afce26138e344b4ab9 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
image = plt.imread("gardens.jpg")
# Create a figure with two subplots using 'subplot_mosaic'
# Argument needs to be a 2D array, which is why
# there are two sets of square brackets
fig, ax = plt.subplot_mosaic(
[["Left", "Right"]]
)
# You can now use a "dictionary-style" indexing
# to refer to each subplot
ax["Left"].imshow(image)
ax["Left"].axis("off")
# Extract the red channel from the image
image_red = image.copy()
image_red[:, :, 1:] = 0
ax["Right"].imshow(image_red)
ax["Right"].axis("off")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment