【问题标题】:wspace and hspace in subplots, width of axes - python3子图中的 wspace 和 hspace,轴的宽度 - python3
【发布时间】:2020-03-19 03:25:06
【问题描述】:

如何在子图中制作 wspace 和 hspace? 我有一个代码类型:

plt.figure(figsize=(12, 10))

fig1=plt.subplot(231)
plt.plot(x, y)

fig2=plt.subplot(232)
plt.plot(x, y)

fig3=plt.subplot(233)
plt.plot(x, y)

fig4=plt.subplot(234)
plt.plot(x, y)

fig5=plt.subplot(235)
plt.plot(x, y)

fig6=plt.subplot(236)
plt.plot(x, y)

我试图让单个人物的 wspace 更大:

plt.figure(figsize=(12, 10))

fig1=plt.subplot(231)
fig1.subplots_adjust(wspace=2)

错误:

    fig1.subplots_adjust(wspace=2)
AttributeError: 'AxesSubplot' object has no attribute 'subplots_adjust'

以及如何改变所有轴的宽度?

我试过了:

import matplotlib as mpl

mpl.rcParams['lines.linewidth'] = 2

【问题讨论】:

    标签: python python-3.x matplotlib subplot


    【解决方案1】:

    你会得到一个错误,因为 subplot 返回一个 Axes 对象并且 subplots_adjust 是一个 Figure 方法。如果要同时返回 Figure 和 Axes 对象,则需要调用 subplots。否则,您可以简单地调用 plt.subplots_adjust()。

    【讨论】:

    • 谢谢,你是这个意思吗? plt.figure(figsize=(12, 10)) plt.subplots_adjust(wspace=3) plt.subplots_adjust(hspace=3) 没有任何改变。
    • 我的意思是,你可以这样定义你的图形和轴。 fig, ax = plt.subplots(nrows=2, ncols=3) 然后在图形对象上调用 subplots_adjust 。一次调用就够了,一次可以传递多个参数。
    • 我试过了,但是子图有不同的大小,空格没有改变。可以单独设置吗?
    • 等等...是您要更改的每个子图的实际大小吗?因为如果是,那么 subplots_adjust 可能不是您想要的。您希望所有轴的大小相同并填充整个图形还是其他?
    • 好的,所以我会先调用 fig.tight_layout()。然后,如果仍然不满意,请使用 height 和 width 参数调用 subplots_adjust 。它应该可以工作,并为标签提供更多空间。
    猜你喜欢
    • 2019-03-10
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多