5

I am using Google Colab and when I try to draw a graph it comes like thisenter image description here

But I have to plot many graphs, so i used a for loop enter image description here

I expected the graphs to be the same size as in the first image but I got all graphs in compressed form. What should I do to obtain the graphs as the same size as in first image using a for loop.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
SHIVANSHU SAHOO
  • 348
  • 1
  • 3
  • 11
  • Does this answer your question? [How do I get multiple subplots in matplotlib?](https://stackoverflow.com/questions/31726643/how-do-i-get-multiple-subplots-in-matplotlib) – RichieV Sep 05 '20 at 15:25
  • 1
    Besides changing the `figsize` which will only get you so far if you have a limited area for your plot, play around with `nrows` and `ncols` parameters of `plt.subplots`, as in the flagged question – RichieV Sep 05 '20 at 15:27

2 Answers2

2

Try to play with figsize parameter:

fig, ax = plt.subplots(no_of_feature, 1, figsize=(5, 10))  # example
trsvchn
  • 8,033
  • 3
  • 23
  • 30
1

When you do:

fig, ax = plt.subplot(no_of_features,1)

You create a single instance of figure, which has a predefined size. thus it will squeeze all the subplots to fit this figure size.

To increase the figure size you should run with the size the you wish before calling plt.subplot:

plt.rcParams['figure.figsize'] = [12, 8]

Or you can create a new plot in each iteration in a different figure, which each image will have the original one size.

As @RichieV suggested, it also advisable to use different nrows/ncols to spread the subplots in the image.

David
  • 8,113
  • 2
  • 17
  • 36