【问题标题】:Is there a matplotlib function in Python for forcing all subplots inside different figures to have the same x and y axis length?Python 中是否有 matplotlib 函数强制不同图形内的所有子图具有相同的 x 和 y 轴长度?
【发布时间】:2022-12-03 03:31:34
【问题描述】:

我正在测试显示数字的不同方式。我有一个图,它由 12 个子图组成,分为两列。就像是...

fig, ax = plt.subplots(6, 2, figsize= (20,26))

我有另一个代码,它根据分类数据将 12 个子图分成 3 个不同的图形。就像是

figA, ax = plt.subplots(5, 1, figsize= (10,23))
figB, ax = plt.subplots(3, 1, figsize= (10,17))
fig2, ax = plt.subplots(4, 1, figsize= (10,20))

有没有办法确保每个图中的所有子图都具有相同的 x 和 y 轴长度?

【问题讨论】:

标签: python matplotlib plot subplot figure


【解决方案1】:

答案原来很简单。使用可按图中绘图数量缩放的变量。因此,具有更多地块的图形将具有更高的图形大小但相等的地块大小。就像是...

ps = 5 #indicates plot size
figA, ax = plt.subplots(5, 1, figsize= (10, 5*ps))
figB, ax = plt.subplots(3, 1, figsize= (10, 3*ps))
fig2, ax = plt.subplots(4, 1, figsize= (10, 4*ps))

【讨论】:

    【解决方案2】:

    我遇到了类似的问题,尝试将 avg(len(x)) 作为乘数。它适用于所有长度。

    【讨论】:

      猜你喜欢
      • 2021-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-26
      • 2017-09-16
      • 1970-01-01
      • 2013-01-22
      • 1970-01-01
      相关资源
      最近更新 更多