[英]How to use axes programmatically in Gnuplot?
If you need to draw some graphs against x1y1
or x1y2
axes, depending on the maximum y value of each graph, what would be the proper syntax for that?如果您需要针对x1y1
或x1y2
轴绘制一些图形,具体取决于每个图形的最大 y 值,那么正确的语法是什么?
My data file has several columns.我的数据文件有几列。 The first one contains x values, the others y1, y2 and so on.第一个包含 x 值,其他 y1、y2 等等。 After using the stats command, I could easily define each axis value for each graph:使用 stats 命令后,我可以轻松地为每个图形定义每个轴值:
stats '$data_file' u 1:2 nooutput;
y1max = STATS_max_y;
if (y1max > ymax) { y1axis = 'x1y2' } else { y1axis = 'x1y1' };
stats '$data_file' u 1:3 nooutput;
y2max = STATS_max_y;
if (y2max > ymax) { y2axis = 'x1y2' } else { y2axis = 'x1y1' };
...
After that, I can draw the graphs with this plot
cmd之后,我可以用这个plot
cmd 绘制图表
plot '$data_file' using 1:2 axes x1y1 notitle with lines lc rgb 'black' lw 1,\
'' using 1:3 axes x1y2 notitle with lines lc rgb 'green' lw 1;
which works, but it is not programmatically at all.这有效,但它根本不是以编程方式。
But this one doesn't works但是这个不起作用
plot '$data_file' using 1:2 axes @y1axis notitle with lines lc rgb 'black' lw 1,\
'' using 1:3 axes @y2axis notitle with lines lc rgb 'green' lw 1;
where I used the Substitution of string variables as macros
(The character @ is used to trigger substitution of the current value of a string variable into the command line...) which is written in the docs .其中我使用了Substitution of string variables as macros
(字符 @ 用于触发将字符串变量的当前值替换到命令行中......),这是写在docs中的。
Nor the eval
command likes to work for me. eval
命令也不喜欢为我工作。
Could you please provide an example for that purpose, which is working or any a good advise.您能否为此目的提供一个示例,这是有效的或任何好的建议。 THX!谢谢!
I got two errors/warnings when using the above code in a bash script as an oneliner the following way在 bash 脚本中使用上述代码作为 oneliner 时,我收到了两个错误/警告,方法如下
echo "gnuplot cmds;plot ..." | gnuplot
As written in the docs, the macro could not be expanded the same time as it is defined , what is the case if written on the same line.正如文档中所写,宏无法在定义的同时扩展,如果写在同一行会怎样。
To avoid the above mistake we have to use only为避免上述错误,我们只需要使用
echo
-e
"gnuplot cmds;
\n
plot..." | gnuplot
echo
-e
"gnuplot cmds;
\n
plot..." | gnuplot
plot..." | gnuplot
and it works like it should.它像它应该的那样工作。
Credits to @Christoph and @Ethan who put me on the right track.感谢@Christoph 和@Ethan,他们让我走上了正轨。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.