简体   繁体   English

matplotlib pyplot:子图大小

[英]matplotlib pyplot: subplot size

If I plot a single graph as below, it will be of size (x * y). 如果我按如下所示绘制单个图形,则其大小为(x * y)。

import matplotlib.pyplot as plt
plt.plot([1, 2], [1, 2])

However, if I plot 3 sub-graphs in the same row, each of them will be of size ((x / 3) * y). 但是,如果我在同一行中绘制3个子图,则每个子图的大小将为((x / 3)* y)。

fig, ax = plt.subplots(1, 3, sharey = True)
for i in range(3):
    ax[i].plot([1, 2], [1, 2])

How can I obtain these 3 subplots, each of which is of size (x * y)? 如何获得这三个子图,每个子图的大小为(x * y)?

The figure object has a default size that does not know about the number of subplots. 地物对象的默认大小不了解子图的数量。 You can change the figure size when you make the figure to suit your needs though. 但是,您可以根据自己的需要更改图形尺寸。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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