Python 如何解决属性错误:';numpy.ndarray和#x27;对象没有属性';获取图';绘制子地块时

Python 如何解决属性错误:';numpy.ndarray和#x27;对象没有属性';获取图';绘制子地块时,python,pandas,matplotlib,Python,Pandas,Matplotlib,当我试图运行一个代码单元时,我遇到了一个问题。 我试图为数据帧中的每个变量绘制散点图,但遇到了一个我不太确定的错误。你能帮忙吗 我的代码: fig, axes = plt.subplots(nrows=3, ncols=7, figsize=(12,10)) for xcol, ax in zip(df[df.columns], axes): df.plot(kind='scatter', x=xcol, y='price', ax=ax, alpha=0.5, color='r')

当我试图运行一个代码单元时,我遇到了一个问题。 我试图为数据帧中的每个变量绘制散点图,但遇到了一个我不太确定的错误。你能帮忙吗

我的代码:

fig, axes = plt.subplots(nrows=3, ncols=7, figsize=(12,10))
for xcol, ax in zip(df[df.columns], axes):
    df.plot(kind='scatter', x=xcol, y='price', ax=ax, alpha=0.5, color='r')
返回错误: AttributeError:'numpy.ndarray'对象没有属性'get\u figure'

  • fig,axes=plt.子图(nrows=3,ncols=7,figsize=(12,10))
    创建3组7个
    AxesSubplot
    对象
  • 您需要的是将一列压缩到一个子批次,这可以通过使用列表理解解包所有轴子批次,或者使用
    axes.ravel()
    ,然后将它们压缩到列名来完成。
    • 返回展平数组
  • 使用
    df.columns
    ,而不是
    df[df.columns]
    ,来获取列名
#列表将解压所有轴
zip(df.columns,[x代表v轴,x代表v轴,x代表v轴])
#这将导致每个子批次有一个列名
[('col1'

array([[<AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>],
       [<AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>],
       [<AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>]], dtype=object)