gnuplot用sprintf生成p​​lot命令吗? [英] gnuplot generate plot command with sprintf?

查看:108
本文介绍了gnuplot用sprintf生成p​​lot命令吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式生成gnuplot绘图命令,例如:

I want to generate a gnuplot plot command programmatically, like:

plotline = sprintf("'datafile1.dat' using %d:3 with points, '%s' using %d:3 with points",i,targfile,i)
plot plotline

第二行中的'plotline'展开以生成并执行完整的命令,例如:

Where 'plotline' in the second line is expanded to produce and execute a full command like:

plot 'datafile1.dat' using 8:3 with points, 'datafile2.dat' using 8:3 with points

我想这样做是为了在终端中回显"plotline",因此请确定在循环一组列/数据文件/gnuplot脚本中的循环内的任何内容时正在显示什么.

I want to do this in order to echo 'plotline' in the terminal and so be certain exactly what is being shown while cycling through a set of columns / datafiles / whatever inside a loop in a gnuplot script.

有/执行此操作的语法是什么,或者您可以建议另一种方法来报告执行时的plot命令(不拆分为plot命令和另一组命令来报告当前变量状态).

Is there / what is the syntax to do this, or can you suggest another approach to report the plot command as executed (without splitting into a plot command and a separate set of commands to report the current variable states).

谢谢!

推荐答案

为了从某些字符串构造这样的绘图命令,可以使用eval执行包含在字符串中的命令:

In order to construct such a plot command from some strings, you can use eval to execute the commands contained in a string:

plotline = 'x title "mytitle"'
eval('plot '.plotline)

或者,您可以使用set macros:

set macros
plotline = 'x title "mytitle"'
plot @plotline

这将@plotline替换为执行命令之前的字符串变量plotline 的内容.使用plot plotline会将plotline的内容解释为文件名.请注意,从4.6版开始,宏无法在循环中正常工作,但是eval可以正常工作.

This replaces @plotline with the content of the string variable plotline before executing the command. Using plot plotline interpretes the content of plotline as file name. Note, that as of version 4.6 macros don't work properly in loops, but eval works fine.

顺便说一句:如果您未指定自己的标题,则实际的绘图语句将写入绘图图例中.但这不能写入终端输出.

BTW: If you don't specify your own title, then the actual plot statement is written in the plot legend. But that can't be written to the terminal output.

这篇关于gnuplot用sprintf生成p​​lot命令吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆