简体   繁体   中英

How change sizes of subplots in Matplotlib?

I am using Google Colab and when I try to draw a graph it comes like this在此处输入图片说明

But I have to plot many graphs, so i used a for loop在此处输入图片说明

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.

尝试使用figsize参数:

fig, ax = plt.subplots(no_of_feature, 1, figsize=(5, 10))  # example

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM