matplotlib中新行中的plt.annotate()

在matplotlib中是否有方法plt.annotate()使得每个子列表显示在新行中?我正在尝试根据我在下面注释掉的代码来实现某些东西。基本上,我试图消除对每个子列表单独注释的需要,因为不知道子列表的数量,并且我正在寻找一种比循环更好的方法来实现它。

import matplotlib.pyplot as plt


x = [['A','B','C'],['X','Y','Z'],['D','E']] 

plt.annotate(x[0],xy=(0.5,0.5))
plt.annotate(x[1],0.4))
plt.annotate(x[2],0.3))

#plt.annotate(x,0.5))  Is there  a way that each sublist is shown in a new line automatically

plt.show()
h975969910 回答:matplotlib中新行中的plt.annotate()

尝试一下:

x = [['A','B','C'],['X','Y','Z'],['D','E']]
s = ''
for i in x:
    s += (str(i) + '\n')
plt.annotate(s,xy=(0.5,0.5))

如果使用换行符,它将显示三行,但是,您必须将所有内容都转换为字符串。

本文链接:https://www.f2er.com/3130781.html

大家都在问