【问题标题】:matplotlib pyplot: subplot sizematplotlib pyplot:子图大小
【发布时间】:2014-07-18 05:46:59
【问题描述】:

如果我绘制如下图,它的大小将是 (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)?

【问题讨论】:

  • 你可以使图形大小为 ((3*x)*y)。
  • 谢谢。我在想是否有办法指定我想保留其原始大小,而不是指定大小。

标签: python matplotlib


【解决方案1】:

图形对象具有不知道子图数量的默认大小。不过,您可以在制作图形以满足您的需要时更改图形大小。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-21
    • 2017-11-14
    • 2015-08-15
    相关资源
    最近更新 更多