0

I am trying to plot multiple rgb images with matplotlib

the code I am using is:

import numpy as np
import matplotlib.pyplot as plt

for i in range(0, images):
    test = np.random.rand(1080, 720,3)
    plt.subplot(images,2,i+1)
    plt.imshow(test, interpolation='none')

the subplots appear tiny though as thumbnails How can I make them bigger? I have seen solutions using

fig, ax = plt.subplots() 

syntax before but not with plt.subplot ?

KillerSnail
  • 3,321
  • 11
  • 46
  • 64
  • The subplot size is determined by how many subplots you put into the figure; e.g. if you put 10 subplot rows into the figure, each will be (roughly) one tenth of the figure size. You may [create a larger figure](https://stackoverflow.com/questions/332289/how-do-you-change-the-size-of-figures-drawn-with-matplotlib) though. – ImportanceOfBeingErnest Apr 14 '19 at 17:18

1 Answers1

0

plt.subplots initiates a subplot grid, while plt.subplot adds a subplot. So the difference is whether you want to initiate you plot right away or fill it over time. Since it seems, that you know how many images to plot beforehand, I would also recommend going with subplots.

Also notice, that the way you use plt.subplot you generate empy subplots in between the ones you are actually using, which is another reason they are so small.

import numpy as np
import matplotlib.pyplot as plt

images = 4


fig, axes = plt.subplots(images, 1,  # Puts subplots in the axes variable
                         figsize=(4, 10),  # Use figsize to set the size of the whole plot
                         dpi=200,  # Further refine size with dpi setting
                         tight_layout=True)  # Makes enough room between plots for labels

for i, ax in enumerate(axes):
    y = np.random.randn(512, 512)
    ax.imshow(y)
    ax.set_title(str(i), fontweight='bold')

plot

flurble
  • 1,086
  • 7
  • 21