[英]How to change the Y axis range of a matplotlib graph?
我正在編寫代碼來獲取圖表:
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。我應該在代碼中更改什么來做到這一點?
你應該試試這個:
plt.ylim(0, 10)
您可以在將y
繪制在圖表上之前對其進行切片,但您也需要對x
執行此操作。
如果y
值都是整數,則可以執行以下操作:
plt.plot(A[50:],bepn[50:])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.