GNUplot:在图例中使用变量

GNUplot:在图例中使用变量,gnuplot,legend,legend-properties,Gnuplot,Legend,Legend Properties,多亏了这个博客()中的答案,我们可以在GNUplot中绘制峰值。这是我的剧本 xcolumn=1 ycolumn=0 count = 0 plot "test.csv" u (column(xcolumn)):(column(ycolumn)) title "freq" w l, \\ "test.csv" u (column(0)==0 ? (last2y=column(ycolumn), \\ last2x=column(xcolumn), 1/0) : column

多亏了这个博客()中的答案,我们可以在GNUplot中绘制峰值。这是我的剧本

xcolumn=1
ycolumn=0
count = 0


plot "test.csv" u (column(xcolumn)):(column(ycolumn)) title "freq" w l, \\
     "test.csv" u (column(0)==0 ? (last2y=column(ycolumn), \\
     last2x=column(xcolumn), 1/0) : column(0)==1 ? (lasty=column(ycolumn), \\
     lastx=column(xcolumn), 1/0) : lastx) \\
     : \\
     ( column(0) < 2 ? 1/0 : (last2y <= lasty && \\
     column(ycolumn) < lasty) ? (value=lasty, last2y=lasty, last2x=lastx, \\
     count = count +1, \\
     lasty=column(ycolumn), lastx=column(xcolumn), value) : (last2y=lasty, \\
     last2x=lastx, lasty=column(ycolumn), lastx=column(xcolumn), 1/0))  title sprintf("Peaks %d", count) pt 7
xcolumn=1
ycolumn=0
计数=0
绘图“test.csv”u(列(xcolumn)):(列(ycolumn))标题“freq”w l\\
“test.csv”u(列(0)=0?(last2y=列(y列)\\
last2x=列(X列),1/0):列(0)==1?(lasty=列(Y列)\\
lastx=列(X列),1/0:lastx)\\
: \\

(列(0)<2?1/0:(last2y标题字符串在打印实例开始时计算,因此打印期间更改的任何变量在打印标题时都不会更新。)

例如,以下数据文件看起来像[-10:10]域中的sin(x),包含三个局部极大值:

运行peak脚本会在标题中产生
0
,因为
count
在计数结束之前已经计算过:

xcolumn=1
ycolumn=2
count=0

plot "sin.dat" u (column(xcolumn)):(column(ycolumn)) w l, \
"sin.dat" u (column(0)==0 ? (last2y=column(ycolumn), \
last2x=column(xcolumn), 1/0) : column(0)==1 ? (lasty=column(ycolumn), \
lastx=column(xcolumn), 1/0) : lastx) \
: \
( column(0) < 2 ? 1/0 : (last2y < lasty && \
column(ycolumn) < lasty) ? (count=count+1, value=lasty, last2y=lasty, last2x=lastx, \
lasty=column(ycolumn), lastx=column(xcolumn), value) : (last2y=lasty, \
last2x=lastx, lasty=column(ycolumn), lastx=column(xcolumn), 1/0)) pt 7 t sprintf("No. of peaks = %i", count)
xcolumn=1
ycolumn=2
计数=0
绘图“sin.dat”u(列(X列)):(列(Y列))w l\
“sin.dat”u(列(0)=0?(last2y=列(y列)\
last2x=列(X列),1/0):列(0)==1?(lasty=列(Y列)\
lastx=列(X列),1/0:lastx)\
: \
(第(0)列<2?1/0:(last2y

这里的诀窍是跳过此标题,然后使用与以前相同的样式绘制一个伪函数:

xcolumn=1
ycolumn=2
count=0

plot "sin.dat" u (column(xcolumn)):(column(ycolumn)) w l, \
"sin.dat" u (column(0)==0 ? (last2y=column(ycolumn), \
last2x=column(xcolumn), 1/0) : column(0)==1 ? (lasty=column(ycolumn), \
lastx=column(xcolumn), 1/0) : lastx) \
: \
( column(0) < 2 ? 1/0 : (last2y < lasty && \
column(ycolumn) < lasty) ? (count=count+1, value=lasty, last2y=lasty, last2x=lastx, \
lasty=column(ycolumn), lastx=column(xcolumn), value) : (last2y=lasty, \
last2x=lastx, lasty=column(ycolumn), lastx=column(xcolumn), 1/0)) pt 7 not ,\
1/0 w p lc 2 pt 7 t sprintf("No. of peaks = %i", count)
xcolumn=1
ycolumn=2
计数=0
绘图“sin.dat”u(列(X列)):(列(Y列))w l\
“sin.dat”u(列(0)=0?(last2y=列(y列)\
last2x=列(X列),1/0):列(0)==1?(lasty=列(Y列)\
lastx=列(X列),1/0:lastx)\
: \
(第(0)列<2?1/0:(last2y

您可以使用
lc[number]
更改颜色;每个数字对应一种颜色。
lc rgb“blue”
等应该可以。非常感谢米格尔的帮助。您帮了我很大的忙。我正在努力忽略误报,并问了另一个问题: