Matplotlibe image size

Изменить размер изображения для subplot можно так:

fig, axs = plt.subplots(nrows=3, ncols=3)
fig.set_figheight(25)
fig.set_figwidth(25)

Статья на эту тему.

Иногда нужно контролировать общий размер изображения и его разрешение.

You just need to call pl.figure(figsize=…) before you call the pl.colorbar (and all the other stuff)

import matplotlib.pyplot as plt
%matplotlib inline

def plot(fs,dpi):
    fig, ax=plt.subplots(figsize=fs, dpi=dpi)
    ax.set_title("Figsize: {}, dpi: {}".format(fs,dpi))
    ax.plot([2,4,1,5], label="Label")
    ax.legend()

figsize=(2,2)
for i in range(1,4):
    plot(figsize, i*72)

dpi=72
for i in [2,4,6]:
    plot((i,i), dpi)

В чем разница между figsize и dpi смотри тут. Вкратце:

Figure size (figsize) determines the size of the figure in inches. This gives the amount of space the axes (and other elements) have inside the figure. The default figure size is (6.4, 4.8) inches in matplotlib 2. A larger figure size will allow for longer texts, more axes or more ticklabels to be shown.

Dots per inches (dpi) determines how many pixels the figure comprises. The default dpi in matplotlib is 100. A figure of figsize=(w,h) will have

Пример

from matplotlib.pyplot import figure

figure(figsize=(8, 6), dpi=80)

figure(figsize=(1,1)) would create an inch-by-inch image, which would be 80-by-80 pixels unless you also give a different dpi argument.

референс

[matplotlibe]

>>> На главную