值图形中的直线样条曲线,但y

2024-09-26 18:20:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我想生成一个像下面的链接图

http://en.wikipedia.org/wiki/Reaction_coordinate

通过对安装的python库的计算生成的图形。 我希望这条线是光滑的cspline gnuplot类型

E_ads=234.4211,E_dis=0.730278和E_reac=-0.8714

有人能帮我吗

from ase import *
from ase.calculators.jacapo import *
import Gnuplot as gp
# -- Read in all energies
datadict = {'H2O' :'water.nc',
            'Pt' :'out-Pt.nc',
            'H2OPt' :'H2O.Pt.nc',
            'OHPt' :'OHPt.nc',
            'HPt' :'HPt.nc',
}
E = {}

for label, file in datadict.items():
    print 'Reading energy for %5s from file %20s' % (label, file),
    atoms = Jacapo.read_atoms(file)
    E[label] = atoms.get_potential_energy()
    print '\tE = %14.6f eV'% E[label]
print     

# -- Calculate adsorption and disassociation energies
E_ads = (E['H2OPt'] - 2*E['H2O'] - E['Pt'])/2
print 'H2O adsorption energy on Pt:'
print 'E_ads =', E_ads, 'eV\n'

E_dis = E['HPt'] - E['Pt'] + E['OHPt'] - E['Pt'] - E['H2O']
print 'H2O -> OH + H disassociation energy on Pt:'
print 'E_dis =', E_dis, 'eV\n'

E_reac = E['H2OPt'] - E['HPt'] - E['OHPt'] + E['Pt']
print 'H2O@Pt -> OH@Pt +H@Pt reaction energy on Pt:'
print 'E_reac =', E_reac, 'eV\n'
# -- Collect reaction path
Epath = np.asarray([1.0, E_ads, E_dis, E_reac])
PathLabels= ['']
# -- Plot the reaction path
import pylab as p
import numpy as np
import matplotlib.path as mpath
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
from scipy.interpolate import spline
import matplotlib.pyplot as plt
from numpy import array, linspace
from scipy.interpolate import spline
fig = p.figure(1)
sp = p.subplot(1,1,1)
p.plot(Epath, color='black', linestyle=':', linewidth=2.0, alpha=0.8)
p.text(0.37, 10.05, 'Free H$_2$O',fontsize=12, color='black',ha='right', va='bottom', alpha=1.0)
p.text(1.1, 238, 'H$_2$O + Pt',fontsize=12, color='black',ha='right', va='bottom', alpha=1.0)
p.title('H$_2$O disassociation')
p.ylabel('Energy [eV]')
p.xlabel('Reaction path')
#p.xlim([-0.5, 2.5])
#p.ylim([-0.5, 1.5])
sp.get_xaxis().set_ticks([]) # Turn off ticks on xaxis
#p.savefig('Teste.png')
p.show()

Tags: fromimportptaslabelenergyadsprint
1条回答
网友
1楼 · 发布于 2024-09-26 18:20:53

只需执行以下操作,即可绘制数据的常规三次样条曲线:

plot(np.linspace(0,3),spline([0,1,2,3],Epath,np.linspace(0,3)))

会产生类似于:

enter image description here

但我怀疑这不是你想要的。您可能需要使用类似于Monotone splines或{a2}的方法来获得与Wikipedia链接中显示的曲线相同的形状。我不相信这些插值方法中的任何一个目前都在scipy中实现。在

如果你对这些曲线的数学形式有一个粗略的概念,你可以随时拟合你自己的近似函数,然后把函数钳制在这个范围之外。例如:

^{pr2}$

会产生:

enter image description here

它至少“看起来”像你链接到的曲线,即使它不是正确的拟合。在

相关问题 更多 >

    热门问题