繁体   English   中英

'TypeError:'function' 类型的参数不可迭代' 如何使 function 可迭代?

[英]'TypeError: argument of type 'function' is not iterable' How do I make a function iterable?

我正在尝试使用 python 中的 seaborn 生成 6 个小提琴子图。 我遇到了一个错误,指出“function 类型的参数不可迭代”。 我想知道我的代码中是否缺少某些内容,或者我的 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```

您不会遍历 function; 您可能会使用它来生成可迭代的,但 function 本身不是可迭代的 object。 (从技术上讲,在 Python 中构造一个 object 是可迭代和可调用的,但是......不。这不是解决这个问题的方法。)

我很确定这句话毫无意义,并表明您可能由于不了解 function 的工作原理而使整个事情过于复杂:

sns.violinplot(x = x in sns.violinplot ...

通过查看文档( https://seaborn.pydata.org/generated/seaborn.violinplot.html ),它看起来可能不是您想要的整个循环:

axs = sns.violinplot(y=VAR)

或类似的东西?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM