如何在Python中绘制所有解释变量与响应变量的多重散点图。无论我将squeeze设置为True还是False,都会生成以下错误:TypeError: ‘AxesSubplot’ object is not subscriptable
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])
回答:
你的Axes数组名为axes
,而不是ax
。你应该调用sns.scatterplot(..., ax=axes[i,j])
请注意,axes
是一个二维数组,因此你需要两个计数器,或者遍历一个平坦的axes数组:
for ax,col in zip(axes.flat, chef_num.columns[1:]): sns.scatterplot(x=chef_num[col], y=chef_num['REVENUE'], ax=ax)