2015-12-11 28 views
3

让我们说我有以下简单的gnuplot文件:gnuplot的:一个绘图命令的禁用部分

set term pdf 
set output "test.pdf" 

plot\ 
    sin(x),\ 
    cos(x),\ 
    0.5 

现在我只想暂时发表意见符合cos(x),\

但是,使用注释字符#会导致错误的gnuplot命令。

我正在寻找解决方案而不移动代码行。我只想使用我的编辑器的切换评论功能。

+0

有没有办法得到这个,请参阅http://stackoverflow.com/q/30868244/2604213 – Christoph

+0

这太糟糕了。我认为这将是gnuplot的一个很好的扩展,可以在注释中选择性地禁用行延续。 – Hotschke

+0

也有关于邮件列表的讨论:http://gnuplot.10905.n7.nabble.com/line-continuation-of-comments-td11266.html http://gnuplot.10905.n7.nabble.com/Comments -and-continuation-lines-td19020.html – Hotschke

回答

4

这是一种解决方法。您可以动态解析脚本以删除#的行。使用grep

grep -v "#" script | gnuplot 

将成功地解析此:

plot\ 
    sin(x),\ 
    #cos(x),\ 
    0.5 

其中script是包含上述代码的文件的名称。

+0

这是一个很好的解决方法。感谢分享。 – Hotschke

0

虽然gnuplot不直接支持您要求的内容,但您大概可以构建解决方法。 作为gnuplot的不绘制未定义的值,这可能工作

identity = 0 
#identity= 1 
name=identity ? "cos(x)" : '' 

plot sin(x), (1/identity)*cos(x) t name 

根据是否开启或关闭评论,变量identity将具有价值01
在第一种情况下(即,identity = 0),(1/identity)(因此(1/identity)*cos(x))的结果未定义,并且gnuplot不会绘制它。
删除上面示例中的注释identity将等于1。在这种情况下,(1/identity)的结果是1,因此(1/identity)*cos(x)cos(x)相同。

以显示正确的标题(identity = 1)或无标题所有的(如果identity=0),我添加了这行name=identity ? "cos(x)" : ''