【问题标题】:Error when trying to unpack axes from plt.subplots() [duplicate]尝试从 plt.subplots() 解包轴时出错 [重复]
【发布时间】:2019-03-06 15:58:32
【问题描述】:

我有一个 iris 数据集,我正在尝试为 iris 数据集的所有 4 列绘制分布图:

df.columns    
['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)',
           'petal width (cm)']

我想绘制我尝试过的值的分布。

fig, (ax1,ax2,ax3,ax4)= plt.subplots(2,2)
sns.distplot(a = df.iloc[:,0])

我得到一个 ValueError:

ValueError                                Traceback (most recent call last)
<ipython-input-265-58940645d27a> in <module>()
----> 1 fig, (ax1,ax2,ax3,ax4)= plt.subplots(2,2)
      2 sns.distplot(a = df.iloc[:,0])

ValueError: not enough values to unpack (expected 4, got 2)

【问题讨论】:

    标签: python seaborn


    【解决方案1】:

    plt.subplots(2,2)returns a 2x2 array。如果要拆包,需要提供正确的形状:

    fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2,2)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-03
      • 2017-05-10
      • 1970-01-01
      • 2020-06-15
      • 1970-01-01
      • 2021-06-18
      • 2022-01-11
      相关资源
      最近更新 更多