matplotlib pyplot: 子图大小
如果我画一个单独的图,它的大小会是 (x * y)。
import matplotlib.pyplot as plt
plt.plot([1, 2], [1, 2])
但是,如果我在同一行画3个小图,每个小图的大小就变成了 ((x / 3) * y)。
fig, ax = plt.subplots(1, 3, sharey = True)
for i in range(3):
ax[i].plot([1, 2], [1, 2])
我该怎么做才能让这3个小图的大小都变成 (x * y) 呢?
1 个回答
6
图形对象有一个默认的大小,它并不知道你要放多少个子图。不过,你在创建图形的时候可以根据自己的需要来调整图形的大小。
import matplotlib.pyplot as plt
nx = 3
ny = 1
dxs = 8.0
dys = 6.0
fig, ax = plt.subplots(ny, nx, sharey = True, figsize=(dxs*nx, dys*ny) )
for i in range(nx):
ax[i].plot([1, 2], [1, 2])