【发布时间】:2017-11-19 18:56:59
【问题描述】:
我在Insert image into pie chart slice的帮助下构建了一组饼图 我的图表看起来很棒,现在我需要将所有 6 个图表放在一个 2x3 图形中,并在共享的 x 和 y 轴上使用公共刻度线。 首先,我正在查看子图,并认为我可以让它工作。我下载了一些示例并开始尝试一些东西。
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'
为什么它是数组或轴,以及为什么 2X1 有效而 1X2 无效? 我希望我能更好地理解文档。谢谢。
【问题讨论】:
标签: python numpy matplotlib plot