如何用matplotlib和mendeleev添加多个箭头而不用一一写?

问题描述 投票:0回答:1

在我的图表中,我有一条根据原子序数给出电负性的曲线。我希望从门捷列夫库给出的每个值开始一个箭头,精确给出电负性的值。 我不想一一写出箭头,而是自动完成。

from mendeleev import element
import matplotlib.pyplot as plt
 
x, y = range(1,108), [element(i).en_pauling for i in range(1,108)]
for i in range(1,108):
    print(x[i-1], y[i-1])
  
plt.figure()
plt.plot(x, y)
plt.xticks([0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 108])
plt.yticks([0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5])
plt.xlim(0,108)
plt.ylim(0,5)
plt.grid()
plt.savefig("En_pauling.png")

plt.xlabel("Le numéro atomique Z")  
plt.ylabel("Electronégativité selon Pauling")
plt.title("Evolution de l'électronégativité selon Pauling des 108 premiers éléments")
plt.plot(x,y,color='purple', marker = '+')
plt.plot(x, y, 'c')
plt.annotate('Carbone EN=2.6', xy=(6, 2.55), xytext=(25, 4.25), 
arrowprops={'facecolor':'black', 'shrink':0.05} )
plt.annotate('Fer EN=1.83', xy=(26, 1.83), xytext=(30, 3.25), 
arrowprops={'facecolor':'black', 'shrink':0.05} )
plt.annotate('Or EN=2.6', xy=(79, 2.54), xytext=(80, 3.5), 
arrowprops={'facecolor':'black', 'shrink':0.05} )
plt.show()

我不想一一编写它们,而是在使用门捷列夫库时自动完成。 如果可能的话,箭头可以垂直于我的曲线开始吗?

python matplotlib
1个回答
0
投票

我建议更改策略并使用plotlybokeh之类的东西,并在将鼠标悬停在点上时显示实际值。前段时间我用散景制作了一个应用程序,如果你感兴趣的话,相关功能是here

© www.soinside.com 2019 - 2024. All rights reserved.