我正在写一个代码来得到一个图形
import pandas as pd
import matplotlib.pyplot as plt
#importing the excel sheet with elements, mass and atomic number
x=pd.read_excel('Elements.xlsx')
#converting atomic number column to a list
Z=x['Z'].tolist()
#converting mass column to another list
A=x['A'].tolist()
#giving the constants some value
a1,a2,a3=14.1,13,0.595
#finding binding energy per nucleon of each element using liquid drop model
bepn=[]
for i in range(0,118):
y=a1-(a2/(A[i])**(1/3))-(a3*Z[i]*(Z[i]-1)/(A[i])**(4/3))
bepn.append(y)
#plotting the graph
plt.plot(A,bepn)
plt.xlabel("Atomic mass")
plt.ylabel("Binding energy per nucleon")
plt.show
得到的曲线图显示y轴的范围从-50到10。 但我希望y轴从0到9。 我应该在代码中更改什么来实现这一点?
您可以先对y
进行切片,然后再在图上绘制,但是您也需要对x
进行切片。
如果y
值都是整数,则可以执行以下操作:
plt.plot(A[50:],bepn[50:])