Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何更改matplotlib图形的Y轴范围?_Python_Pandas_Matplotlib - Fatal编程技术网

Python 如何更改matplotlib图形的Y轴范围?

Python 如何更改matplotlib图形的Y轴范围?,python,pandas,matplotlib,Python,Pandas,Matplotlib,我正在编写一个代码来获取图形: 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

我正在编写一个代码来获取图形:

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:])
你应该试试这个:

plt.ylim(0, 10)

在我看来,这不是matplotlib的问题,而是你计算结合能的方法。我建议你结束这个问题,再问一个新的问题,可能是关于物理或化学的。