如何在 Gnuplot 中为曲线上方的区域着色?

问题描述 投票:0回答:1

我正在使用 Gnuplot 进行数据可视化,我想对曲线上方的区域进行着色,如下图所示:

我想用两种不同的颜色(青色和红色)对曲线上方的区域进行着色,如图所示。

有人可以建议我如何在 Gnuplot 中实现这一目标吗?

提前感谢您的帮助!

punto1=2.159070517372475,-2.150551183049983

punto2=9.999994158286656, 2.6135179349255238e-06


set xlabel  "Distance (Å)"   font ",25"
set ylabel  "Energy (eV)"  font ",25" 
set bmargin at screen 0.20
unset key
set border 15 lw 5
set tics font ",20"
unset grid
set xzeroaxis lw 3 
set format y "%.2f"
set grid
set xtics 1

set key vertical opaque r a

f(x) = -(2 * a * De) * exp(-a * (x - re)) * (1 - exp(-a * (x - re)))

De = 2.35   
a  = 1.82   
re = 1.77   


plot f(x) w l lw 3 lc "green" title "dV/dr"

set yrange [-5:7]
set xrange [0.5:10.5]

replot "punto1" w p pt 7 ps 1 lc "blue" notitle
replot "punto2" w p pt 7 ps 1 lc "blue" notitle

set style fill transparent solid 0.15 noborder

replot f(x) with filledcurves below x1=2 lc "purple" notitle

#filter(x,min,max) = (x > min && x < max) ? x : 1/0
#replot '+' using (filter(\$1, 1, 2.15)):(f(\$1)) with filledcurves above x1 lt 1 notitle 
set terminal pngcairo enhanced font 'Times New Roman,20' fontscale 1.5 size 1200,800
set output '$nombre.png'
set size ratio 0
rep
exit
math gnuplot physics
1个回答
0
投票

这里是使用数组的建议。您需要知道三个 x 坐标:

  1. 第一个过零
    x=1.77
    ,实际上是
    re
    (根据您对
    f(x)
    的定义)
  2. (我假设)
    f(x)
    x=2.1590
  3. 处的最小值
  4. 终点
    x=10
  • 不需要
    replot
    ,您可以在一个绘图命令中完成所有工作
  • every ::1
    仅从第二个值开始绘制数组,请检查
    help every
  • 如果绘制数组,第 2 列是值,
    f($2)
    是该 x 值处的函数值
  • 检查
    help arrays
    help sampling 1D

脚本:(需要 gnuplot>=5.2.0,因为使用数组)

### plot function with differently filled curve
reset session

f(x) = -(2 * a * De) * exp(-a * (x - re)) * (1 - exp(-a * (x - re)))
De = 2.35
a  = 1.82
re = 1.77

set xrange [0.5:10.5]
set yrange [-5:7]
set grid x,y
set xzeroaxis lw 3 
set key noautotitle
set samples 500

array P[3] = [re, 2.15907, 10.0]

plot sample [P[1]:P[2]] f(x) w filledcurves y=0 lc rgb 0xaaffff, \
            [P[2]:P[3]] f(x) w filledcurves y=0 lc rgb 0xffaaaa, \
     f(x) w l lw 3 lc "web-green" title "dV/dr", \
     P every ::1 u 2:(f($2)) w p pt 7 lc "black"
### end of script

结果:

© www.soinside.com 2019 - 2024. All rights reserved.