matplotlib pyplot:子图大小 [英] matplotlib pyplot: subplot size

查看:133
本文介绍了matplotlib pyplot:子图大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我绘制一个如下图,它的大小为 (x * y).

If I plot a single graph as below, it will be of size (x * y).

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

但是,如果我在同一行中绘制 3 个子图,则每个子图的大小都是 ((x/3) * y).

However, if I plot 3 sub-graphs in the same row, each of them will be of size ((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)?

How can I obtain these 3 subplots, each of which is of size (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])

这篇关于matplotlib pyplot:子图大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆