【问题标题】:Gnuplot restricting the domain of multiple data files plotted onto one plotGnuplot 限制绘制到一个图上的多个数据文件的域
【发布时间】:2015-09-14 14:11:36
【问题描述】:

我正在使用我编写的 .plt 文件访问来自许多不同文件的数据。只有每个数据集的特定域是重要的。我正在尝试仅将每个数据集的特定域绘制到一个图表上。

每个域中的数据对应一个峰值。我想绘制每个峰值,然后将指数衰减函数拟合到峰值。

这是我的绘图文件中的代码:

set xlabel "Time (ms)"
set ylabel "voltage"

set title "T1 time for Isopropyl Alcohol"
dir='C:\Users\Daniel\Desktop\College\modern lab\gp501-win64-mingw\gnuplot\bin\data files\isoproply_alc_t1\'
unset key
set style data linespoints
x(v, left, right) = (v >= left && v <= right ? v : 1/0)
plot dir.'nmr-t1-isopropyl-dt10' using (x($0*0.01, 3, 7)):1, \
     dir.'nmr-t1-isopropyl-dt50' using (x($0*0.01, 20, 40)):1, \
     dir.'nmr-t1-isopropyl-dt100' using (x($0*0.01, 40, 60)):1, \
     dir.'nmr-t1-isopropyl-dt150' using (x($0*0.01, 70, 80)):1, \
     dir.'nmr-t1-isopropyl-dt200' using (x($0*0.01, 99, 101)):1, \
     dir.'nmr-t1-isopropyl-dt230' using (x($0*0.01, 114, 116)):1, \
     dir.'nmr-t1-isopropyl-dt250' using (x($0*0.01, 124, 126)):1, \
     dir.'nmr-t1-isopropyl-dt270' using (x($0*0.01, 134, 136)):1, \
     dir.'nmr-t1-isopropyl-dt290' using (x($0*0.01, 144, 146)):1, \
     dir.'nmr-t1-isopropyl-dt300' using (x($0*0.01, 149, 151)):1, \
     dir.'nmr-t1-isopropyl-dt320' using (x($0*0.01, 159, 161)):1, \
     dir.'nmr-t1-isopropyl-dt340' using (x($0*0.01, 169, 171)):1, \
     dir.'nmr-t1-isopropyl-dt360' using (x($0*0.01, 178, 183)):1, \
     dir.'nmr-t1-isopropyl-dt400' using (x($0*0.01, 198, 201)):1, \
     dir.'nmr-t1-isopropyl-dt430' using (x($0*0.01, 213, 217)):1, \
     dir.'nmr-t1-isopropyl-dt470' using (x($0*0.01, 233, 236)):1, \
     dir.'nmr-t1-isopropyl-dt580' using (x($0*0.01, 289, 291)):1, \
     dir.'nmr-t1-isopropyl-dt620' using (x($0*0.01, 309, 311)):1, \
     dir.'nmr-t1-isopropyl-dt650' using (x($0*0.01, 324, 326)):1, \
     dir.'nmr-t1-isopropyl-dt700' using (x($0*0.01, 348, 352)):1, \
     dir.'nmr-t1-isopropyl-dt750' using (x($0*0.01, 374, 376)):1, \
     dir.'nmr-t1-isopropyl-dt800' using (x($0*0.01, 399, 401)):1, \
     dir.'nmr-t1-isopropyl-dt850' using (x($0*0.01, 424, 426)):1, \
     dir.'nmr-t1-isopropyl-dt900.2' using (x($0*0.01, 449.5, 451)):1

这给出了正确的域。

现在我想在 y 轴上翻转数据点,越过某个任意 x 值。我想让它们变成负数。

我尝试了flipy 命令,但这不起作用。

【问题讨论】:

    标签: plot gnuplot xrange


    【解决方案1】:

    Gnuplot 不支持在单个 plot 命令中为每个数据文件指定单独的范围。这仅适用于函数。

    您必须过滤 using 语句中的数据,方法是为所需范围之外的所有点指定值 1/0,这会使相应的点无效:

    left = 3
    right = 7
    plot 'file.dat' using ($0 > left && $0 < right ? $0 : 1/0):1
    

    为了使命令更具可读性,您还可以将过滤放在一个函数中。还有一些其他的方法可以提高代码的可读性:

    • 定义一个变量dir,其中包含文件的路径。然后通过. 运算符将数据文件名与该变量连接起来:

      dir = 'C:\my path\'
      plot dir.'file.dat' ...
      
    • 使用unset key可以全局跳过键(图例)

    • 您可以使用set style data linespoints 全局设置数据文件的绘图样式

    所以你的脚本可能看起来像

    set xlabel "Time (ms)"
    set ylabel "voltage"
    set format y "%s"
    
    set title "T1 time for Isopropyl Alcohol"
    dir='C:\Users\Daniel\Desktop\College\modern lab\gp501-win64-mingw\gnuplot\bin\data files\isoproply_alc_t1\'
    unset key
    set style data linespoints
    x(v, left, right) = (v >= left && v <= right ? v : 1/0
    plot dir.'nmr-t1-isopropyl-dt10' using (x($0*0.01, 3, 7)):1, \
         dir.'nmr-t1-isopropyl-dt50' using (x($0*0.01, 20, 40)):1, \
         dir.'nmr-t1-isopropyl-dt100' using (x($0*0.01, 40, 60)):1, \
         dir.'nmr-t1-isopropyl-dt150' using (x($0*0.01, 70, 80)):1
    

    【讨论】:

    • 效果很好!我的所有峰都有一个清晰的情节。我应该从哪里开始,以便我可以拟合指数衰减函数来拟合这些峰值? (它应该看起来像一个包含所有数据点的信封
    • 您必须将衰减曲线中的所有点放在一个文件(或内联数据集)中才能使用“拟合”。单线:set table $T1data; replot; unset table; fit I-2*I*exp(-x/T1) $T1data us 1:2 noerr via I,T1(我假设反转恢复;-))您可能想要调整每个回声的左右限制,因此 x() 只返回一个值。
    • 这是反转恢复!谢谢。我仍然无法使用 gnuplot。我可能会切换回数学!
    • 嗯,与mathematica 相比,gnuplot 只是一个绘图程序,并不用于数据处理。记住这一点
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-13
    • 1970-01-01
    相关资源
    最近更新 更多