【问题标题】:How to pull multi scatterplot of all explanatory variables to response variables in python如何将所有解释变量的多散点图拉到python中的响应变量
【发布时间】:2020-06-27 02:21:54
【问题描述】:

如何将所有解释变量的多散点图拉到 python 中的响应变量。生成的错误如下,无论我将挤压设置为真还是假。 TypeError: 'AxesSubplot' 对象不可下标

f, axes = plt.subplots(6, 4, figsize=(20, 20), sharex=False, squeeze=False)

for i,col in enumerate(chef_num.columns[1:]):

    sns.scatterplot(x=chef_num[col], y=chef_num['REVENUE'], ax=ax[i])

【问题讨论】:

  • 什么是ax?错误是由ax[i] 引起的。我假设它是一个轴,因此正如错误所说,它不能下标。

标签: python pandas matplotlib machine-learning seaborn


【解决方案1】:

您的 Axes 数组称为 axes,而不是 ax. 您应该调用 sns.scatterplot(..., ax=axes[i,j])

请注意,axes 是一个二维数组,因此您需要两个计数器,或者迭代一个扁平的轴数组:

for ax,col in zip(axes.flat, chef_num.columns[1:]):
    sns.scatterplot(x=chef_num[col], y=chef_num['REVENUE'], ax=ax)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-21
    • 2020-03-30
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    相关资源
    最近更新 更多