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)?

图形对象的默认大小不知道子图的数量。当你制作图形时,你可以改变图形的大小来满足你的需要。

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])

最新更新