0
$\begingroup$

coffee

horse

As a beginner, can someone please help me with this? Is there any way to show both pictures in a single cell's output? My output could only display one picture. Thank you for your time and attention!

Here is my code:

from skimage import data
image_coffee = data.coffee()
image_horse = data.horse()
fig = plt.figure(dpi=100)
plt.imshow(image_coffee)
plt.imshow(image_horse)
$\endgroup$
1

1 Answer 1

0
$\begingroup$

One way to do it (without getting into lots of the inner-workings of Jupyter notebooks), it to use two matplotlib Axes in one plot. Then you show one image in each of these:

from skimage import data
image_coffee = data.coffee()
image_horse = data.horse()
fig, axs = plt.subplots(1, 2, figsize=(15, 8))  # one row of Axes, two columns = 2 plots

The axs variables is a list containing the two Axes, so just access each one and plot your image on it like this:

axs[0].imshow(image_coffee)
axs[1].imshow(image_horse)

If the plots don't pop automatically, either run plt.show() or make sure your notebook has executed %matplotlib inline in a cell.

$\endgroup$
1
  • $\begingroup$ Thank you for the help! $\endgroup$
    – mjf88530
    Feb 7, 2021 at 12:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.