Gnuplot:使用函数转换数据文件的列并绘制转换后的数据和函数
Gnuplot: use a function to transform a column of a data file and plot the transformed data and the function
我有一个名为:energy_vs_volume.dat
的文件如下:
# Volume Energy
123.598570 -1.883015140352E+03
124.960411 -1.883015431207E+03
126.122583 -1.883015514359E+03
126.332431 -1.883015514750E+03
我有一个函数可以将 energy
转换为 pressure
,如下所示:
E0=-1883.01544309
B0=32.13
V0=126.4025
B0_prime=-0.95
f0=(3.0/2.0)*B0
f1(x)=((V0/x)**(7.0/3.0))-((V0/x)**(5.0/3.0))
f2(x)=((V0/x)**(2.0/3.0))-1
P(x)= f0*f1(x)*(1+(3.0/4.0)*(B0_prime-4)*f2(x))
我想在同一个情节中作画:
目标 #1:函数 P(x)
目标 #2:文件 energy_vs_volume.dat
中 Energy
的所有 4 行离散数据,使用函数将其转换为压力,并绘图这4点为y axis: pressure
; x axis: volume
到目前为止,我已经做到了:
set encoding utf8
set termoption enhanced
E0=-1883.01544309
B0=32.13
V0=126.4025
B0_prime=-0.95
f0=(3.0/2.0)*B0
f1(x)=((V0/x)**(7.0/3.0))-((V0/x)**(5.0/3.0))
f2(x)=((V0/x)**(2.0/3.0))-1
P_Birch_Murnaghan(x)= f0*f1(x)*(1+(3.0/4.0)*(B0_prime-4)*f2(x))
set xrange [123:138]
plot P_Birch_Murnaghan(x) with line lt -1 lw 3
这打印了 P(x)
-> 目标 #1
的连续函数
为了使 目标 #2 成为可能,我在脚本中添加了以下内容:
plot "energy_vs_volume.dat" using (P(x)):2 with line lt -1 lw 3
或与$
类似,但它不起作用。
如果你能帮助我,我将不胜感激。
编辑:
我需要知道转换的确切值(4 个体积数据产生的压力)。有没有办法将输出重定向到文件?类似于 plot energy_vs_volume.dat" using 1:(P()) > file.txt
?
的想法
使用
plot "energy_vs_volume.dat" using 1:(P())
将函数 P(x)
应用到您的数据。要将计算值写入文件,请将 plot 命令包装在 set/unset table
对中:
plot "energy_vs_volume.dat" using 1:(P())
set table "output.dat"
replot
unset table
生成的文件包含三列,即 using
语句给出的值,第三列中的一个字符指示值是否在范围内 (i
)、超出范围范围 (o
) 或未定义 (u
).
我有一个名为:energy_vs_volume.dat
的文件如下:
# Volume Energy
123.598570 -1.883015140352E+03
124.960411 -1.883015431207E+03
126.122583 -1.883015514359E+03
126.332431 -1.883015514750E+03
我有一个函数可以将 energy
转换为 pressure
,如下所示:
E0=-1883.01544309
B0=32.13
V0=126.4025
B0_prime=-0.95
f0=(3.0/2.0)*B0
f1(x)=((V0/x)**(7.0/3.0))-((V0/x)**(5.0/3.0))
f2(x)=((V0/x)**(2.0/3.0))-1
P(x)= f0*f1(x)*(1+(3.0/4.0)*(B0_prime-4)*f2(x))
我想在同一个情节中作画:
目标 #1:函数 P(x)
目标 #2:文件 energy_vs_volume.dat
中 Energy
的所有 4 行离散数据,使用函数将其转换为压力,并绘图这4点为y axis: pressure
; x axis: volume
到目前为止,我已经做到了:
set encoding utf8
set termoption enhanced
E0=-1883.01544309
B0=32.13
V0=126.4025
B0_prime=-0.95
f0=(3.0/2.0)*B0
f1(x)=((V0/x)**(7.0/3.0))-((V0/x)**(5.0/3.0))
f2(x)=((V0/x)**(2.0/3.0))-1
P_Birch_Murnaghan(x)= f0*f1(x)*(1+(3.0/4.0)*(B0_prime-4)*f2(x))
set xrange [123:138]
plot P_Birch_Murnaghan(x) with line lt -1 lw 3
这打印了 P(x)
-> 目标 #1
为了使 目标 #2 成为可能,我在脚本中添加了以下内容:
plot "energy_vs_volume.dat" using (P(x)):2 with line lt -1 lw 3
或与$
类似,但它不起作用。
如果你能帮助我,我将不胜感激。
编辑:
我需要知道转换的确切值(4 个体积数据产生的压力)。有没有办法将输出重定向到文件?类似于 plot energy_vs_volume.dat" using 1:(P()) > file.txt
?
使用
plot "energy_vs_volume.dat" using 1:(P())
将函数 P(x)
应用到您的数据。要将计算值写入文件,请将 plot 命令包装在 set/unset table
对中:
plot "energy_vs_volume.dat" using 1:(P())
set table "output.dat"
replot
unset table
生成的文件包含三列,即 using
语句给出的值,第三列中的一个字符指示值是否在范围内 (i
)、超出范围范围 (o
) 或未定义 (u
).