Gnuplot 多列适合(不是 Multi-branch)

Gnuplot Multi Column fit (not Multi-branch)

我有数据文件“y.csv”,其中包含一个实验的多个运行(数据集)列,我想同时适合一个函数。它应该像 plot for [i=2:*] "y.csv" using 1:i 自动容纳文件中的许多列。这是一个简短的示例数据文件:-

,B,C,D,E,F,G,H
01,,,,,,,
02,0.2200,0.2200,0.2080,0.2170,0.1530,,
03,0.2720,0.3230,0.2530,0.2380,0.2620,,
04,0.3900,0.3790,0.3770,0.3760,0.3500,,
05,0.5520,0.5600,0.5450,0.4830,0.4870,,
06,0.6640,0.6300,0.6830,0.6030,0.6520,,
07,0.6440,0.6900,0.6360,0.5960,0.6520,,
08,0.6030,0.6470,0.6190,0.6300,0.6280,,
09,0.5450,0.5890,0.5860,0.6830,0.5540,,
10,0.6370,0.6430,0.5800,0.5270,0.6180,,
11,0.6400,0.5600,0.7190,0.6780,0.7420,,
12,,,,,,,

我可以自动绘制每一列,忽略列 headers,等等:-

  set datafile separator ","
  set datafile columnheaders
  set key autotitle columnheader
  set key top left
  set key title "Run"
  set xrange [1:12]
  set xlabel "Dilution (Proportional to log([]) )"
  set ylabel "Response"
  plot for [i=2:*] "y.csv"  using 1:i  with linespoints

我可以设置一个函数来满足以下条件:-

  sig(x) = 1 / (1+exp(-x))       ; # Appears stable enough in gnuplot
  A = 0.6                        ; # Sigmoid Amplitude
  B = 0.2                        ; # Sigmoid offset
  C = 6                          ; # Center shift on displayed X axis
  K = 1                          ; # Shape factor
  ssig(x) = B + A*sig(K*(x-C))   ; # Fit to this

而且,我可以通过以下方式适应第一个数据列:-

 fit ssig(x)  "y.csv"  using 1:2  via A,B,C,K

但我无法弄清楚如何在所有列上自动执行此操作的语法,就像我可以进行绘图一样。我期待

fit [1:-1:i=2:*]  ssig(x)  "y.csv"  using 1:i  via A,B,C,K

将遍历列。我只是不明白 multi-branch 语法,我想我错过了一些简单的概念。 非常感谢

根据您的评论,您实际上并不是在搜索 multi-branch 拟合,而是希望将所有列合并到一个数据集中并同时使用所有数据点执行拟合。这可以很容易地通过首先将数据文件重塑为数据块来实现:

set datafile separator ","
set table $FITDATA
plot for [i=2:*] "y.csv" u 1:i
unset table
unset datafile separator
sig(x) = 1 / (1+exp(-x))       ; # Appears stable enough in gnuplot
A = 0.6                        ; # Sigmoid Amplitude
B = 0.2                        ; # Sigmoid offset
C = 6                          ; # Center shift on displayed X axis
K = 1                          ; # Shape factor
ssig(x) = B + A*sig(K*(x-C))   ; # Fit to this
set fit errorvariables
fit ssig(x) $FITDATA u 1:2 via A,B,C,K

在数据块中,列由制表符分隔,而不是逗号,因此必须在拟合时将 datafile separator 恢复为默认值,并再次将其改回以进行绘图。也许其他人对此有更清洁的解决方案。 set fit errorvariables 保存拟合误差,以便以后用于绘图标题。

set datafile separator ","
set datafile columnheaders
set key autotitle columnheader
set key top left
set key title "Run"
set xrange [1:12]
set xlabel "Dilution (Proportional to log([]) )"
set ylabel "Response"

plot for [i=2:*] "y.csv" u 1:i w lp, \
ssig(x) lc black lw 3 t "fit", \
keyentry t sprintf("A = %.3f ± %.3f", A, A_err), \
keyentry t sprintf("B = %.3f ± %.3f", B, B_err), \
keyentry t sprintf("C = %.3f ± %.3f", C, C_err), \
keyentry t sprintf("K = %.3f ± %.3f", K, K_err)