【发布时间】:2022-10-18 14:59:00
【问题描述】:
当我尝试绘制 p 值时,我不断遇到这个问题。我不明白序列项 0 是什么。我发现了几个类似的问题,但我仍然不明白在下面的代码中是什么导致了这个问题,也不明白如何解决它。
from statannotations.Annotator import Annotator
cluster_0_wmd = Hub_all_data.loc[(Hub_all_data.Module_ID == 0), "Within_module_degree"].values
cluster_1_wmd = Hub_all_data.loc[(Hub_all_data.Module_ID == 1), "Within_module_degree"].values
cluster_2_wmd = Hub_all_data.loc[(Hub_all_data.Module_ID == 2), "Within_module_degree"].values
with sns.plotting_context('notebook', font_scale=1.4):
# Plot with seaborn
sns.violinplot(**plotting_parameters)
stat_results = [mannwhitneyu(cluster_0_wmd, cluster_1_wmd, alternative="two-sided"),
mannwhitneyu(cluster_0_wmd, cluster_2_wmd, alternative="two-sided"),
mannwhitneyu(cluster_1_wmd, cluster_2_wmd, alternative="two-sided")]
pvalues = [result.pvalue for result in stat_results]
xval = [0,1,2]
plotting_parameters = {
'data': Hub_all_data,
'x': 'Module_ID',
'y': 'Within_module_degree',
'palette': my_col}
pairs = [('cluster_0_wmd', 'cluster_1_wmd'),
('cluster_0_wmd', 'cluster_2_wmd'),
('cluster_1_wmd', 'cluster_2_wmd')]
pairs2 = [(0,1), (0,2), (1,2)]
formatted_pvalues = [f"p={p:.2e}" for p in pvalues]
annotator = Annotator(ax, pairs2, **plotting_parameters)
annotator.set_custom_annotations(formatted_pvalues)
annotator.annotate()
plt.show()
我在 annotator.annotate() 行上得到了错误。这是错误行:
runcell(27, '/Users/albitcabanmurillo/N5_nwxwryan.py')
p-value annotation legend:
ns: p <= 1.00e+00
*: 1.00e-02 < p <= 5.00e-02
**: 1.00e-03 < p <= 1.00e-02
***: 1.00e-04 < p <= 1.00e-03
****: p <= 1.00e-04
Traceback (most recent call last):
File "/Users/albitcabanmurillo/N5_nwxwryan.py", line 421, in <module>
annotator.annotate()
File "/Users/albitcabanmurillo/opt/anaconda3/envs/caiman2/lib/python3.7/site-packages/statannotations/Annotator.py", line 222, in annotate
orig_value_lim=orig_value_lim)
File "/Users/albitcabanmurillo/opt/anaconda3/envs/caiman2/lib/python3.7/site-packages/statannotations/Annotator.py", line 506, in _annotate_pair
annotation.print_labels_and_content()
File "/Users/albitcabanmurillo/opt/anaconda3/envs/caiman2/lib/python3.7/site-packages/statannotations/Annotation.py", line 43, in print_labels_and_content
for struct in self.structs])
TypeError: sequence item 0: expected str instance, numpy.int64 found
【问题讨论】:
-
你在哪一行得到错误?您能否将完整的错误日志粘贴到问题中?
-
嗨@SPSharan,我现在编辑了它,它有错误行和所有细节。谢谢!
标签: python string numpy seaborn