我创建了项目列表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
不能用作换行符。< / p>
ax2 = plt.subplot2grid((8, 10), (6, 0), rowspan=2, colspan=4)
ax2.annotate( proteinlabel, xy=(0.5, 0.5))
如何在子画面框中按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
答案 0 :(得分:1)
您将列表打印为文本,而不是文本本身。所以首先使列表成为一个字符串,然后才能正确解释。
ax2 = plt.subplot2grid((8, 10), (6, 0), rowspan=2, colspan=4)
ax2.annotate( "".join(proteinlabel) , xy=(0.5, 0.5))