Matplotlib数据库:ax.注释从列表中的每一项中,以newlin分隔

2024-05-16 21:49:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建项目列表proteinlabel

proteinlabel = ['K{} - {}\nsum: {:.2e} mean: {:.2e}\n'.format(i+1, name, Harea.sum(), Harea.mean()) 
              for i, (name, Harea) in enumerate(zip(uniprot_label, prot_nHarea))]

print proteinlabel
OUT>> ['K1 - Albumin, Recombinant human\nsum: 1.00e+12 mean: 3.70e+06\n', 'K2 - Antithrombin III from plasma\nsum: 9.36e+11 mean: 5.20e+06\n', 'K3 - Annexin V from human placenta\nsum: 6.79e+11 mean: 6.85e+06\n']

我想按ax.annotate用定义的换行符在子批框中打印这个列表,但是列表的打印方式与OUT>>完全相同,如图所示,\n不能作为换行符。你知道吗

ax2 = plt.subplot2grid((8, 10), (6, 0), rowspan=2, colspan=4)
ax2.annotate( proteinlabel, xy=(0.5, 0.5)) 

enter image description here

如何打印列表中的每一项,在子批框中用换行符ax.annotate(或其他更好的方式)分隔?就像

K1 - Albumin, Recombinant human
sum: 1.00e+12 mean: 3.70e+06
K2 - Antithrombin III from plasma
sum: 9.36e+11 mean: 5.20e+06
K3 - Annexin V from human placenta
sum: 6.79e+11 mean: 6.85e+06

Tags: namefrom列表k2k1outmeansum
1条回答
网友
1楼 · 发布于 2024-05-16 21:49:31

您将列表打印为文本,而不是文本本身。因此,首先让列表成为一个字符串,然后才能正确地解释它。你知道吗

ax2 = plt.subplot2grid((8, 10), (6, 0), rowspan=2, colspan=4)
ax2.annotate( "".join(proteinlabel) , xy=(0.5, 0.5))

相关问题 更多 >