【发布时间】:2020-09-07 00:04:54
【问题描述】:
我正在尝试在 python 中使用 seaborn 生成 6 个小提琴子图。我遇到了一个错误,指出“类型函数的参数不可迭代”。我想知道我的代码中是否缺少某些内容,或者我的 seaborn 导入中是否缺少某些内容。当我在控制台中输入 'print(dir(sns.violinplot))' 时,iter 不存在,我想知道这是否会导致错误?提前致谢!这是我得到的代码和错误消息。
hue = "Mutation"
col = "Subregion"
kind = "violin"
data = M1
title_name = "M1"
VAR = M1.columns[7:]
YL = ["Area (mm^2)","DAPI Cell Count","SST Cell Count","DAPI Cell Density (DAPI/mm^2)","SST Cell Density (SST/mm^2)","SST Cell Density (% SST/DAPI cells)"]
fig, axs = plt.subplots(3, 2,figsize = (8,8))
fig.subplots_adjust(hspace=0.4, wspace=0.4)
axs = axs.reshape(-1)
for k in range(len(VAR)):
sns.violinplot(x = x in sns.violinplot, y = VAR[k], hue = hue, col = None, kind = kind, data = M1,ax=axs[k])
axs[k].set_ylabel(YL[k],fontsize=8)
axs[k].legend_.remove()
axs[-1].legend(loc='upper right', ncol=1,bbox_to_anchor=(1.5,1.5))
plt.show()```
```File "<ipython-input-70-0506b9c647bf>", line 41, in <module>
sns.violinplot(x = x in sns.violinplot, y = VAR[k], hue = hue, col = None, kind = kind, data = M1,ax=axs[k])
TypeError: argument of type 'function' is not iterable```
【问题讨论】:
-
你想用这个语句做什么:
x = x in sns.violinplot? -
x = x in sns.violinplot是导致错误的位,因为它尝试通过sns.violinplot搜索x这是一个函数。不太清楚你想做什么,所以我不知道你应该把它改成什么
标签: python function seaborn typeerror iterable