sách gpt4 ai đã đi

python - 理解 matplotlib.subplots python

In lại Tác giả: Space Dog 更新时间:2023-10-29 22:08:52 25 4
mua khóa gpt4 Nike

我在一些帮助下构建了一组饼图 Insert image into pie chart slice我的图表看起来很棒,现在我需要将所有 6 个图表放在一个 2x3 图形中,并在共享的 x 和 y 轴上使用公共(public)刻度线。一开始我正在查看子图并认为我可以让它工作。我下载了一些示例并开始尝试一些事情。

    f, (a) = (plt.subplots(nrows=1, ncols=1, sharex=True, sharey=True))#,
#squeeze=False, subplot_kw=None, gridspec_kw=None))
print(type(f),'\n',type(a),'\n')#,type(b))

产量:

类'matplotlib.figure.Figure'

类'matplotlib.axes._subplots.AxesSubplot'

同时:

    f, (a) = (plt.subplots(nrows=1, ncols=1, sharex=True, sharey=True, squeeze=False, subplot_kw=None, gridspec_kw=None))
print(type(f),'\n',type(a),'\n')#,type(b))

返回:

类'matplotlib.figure.Figure'

类'numpy.ndarray'

当我这样做时:

f, (a,b) = (plt.subplots(nrows=2, ncols=1, sharex=True, sharey=True, squeeze=False, subplot_kw=None, gridspec_kw=None))
print(type(f),'\n',type(a),'\n',type(b))

我得到了类似的结果,但是如果 nrows=1 和 ncols=2 我会得到一个错误:

    f, (a,b) = (plt.subplots(nrows=1, ncols=2, sharex=True, sharey=True, squeeze=False, subplot_kw=None, gridspec_kw=None))
print(type(f),'\n',type(a),'\n',type(b))

ValueError:没有足够的值来解压(预期 2,得到 1)

但还是这个:

    f, (a , b) = (
plt.subplots(nrows=1, ncols=2, sharex=True, sharey=True))#,
#squeeze=False, subplot_kw=None, gridspec_kw=None))
print(type(f),'\n',type(a),'\n',type(b))

给予类'matplotlib.figure.Figure'

类'matplotlib.axes._subplots.AxesSubplot'

类'matplotlib.axes._subplots.AxesSubplot'

为什么是 or array 或 axes,还有为什么 2X1 有效而 1X2 无效?我真希望我能更好地理解文档。谢谢。

25 4 0
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com