我正在尝试在Gnuplot中使用带有png终端的replot.
如果我执行以下操作,我会在一个图表上得到两个图表,没有任何问题:
plot sin(x)/x
replot sin(x)
Run Code Online (Sandbox Code Playgroud)
现在,如果对png终端类型执行相同操作,则生成的png文件仅包含第一个图.
set terminal png
set output 'file.png'
plot sin(x)/x
replot sin(x)
Run Code Online (Sandbox Code Playgroud)
我在最后错过了什么来获得我的png文件中的第二个情节?
mgi*_*son 15
这实际上是一个非常好的问题,这里的行为取决于终端.一些终端(例如postscript)会为每个终端提供一个新页面replot.你有几个解决方案......
第一种选择:您可以在设置终端/输出之前制作绘图,然后在设置终端/输出后再次重新绘制:
plot sin(x)/x
replot sin(x)
set terminal png
set output 'file.png
replot
Run Code Online (Sandbox Code Playgroud)
如果你想在多个终端中绘制相同的东西,这个选项有时很方便,但我很少用它做任何其他事情.
第二个(更好)选项:您可以将多个图表打包到一个命令中,每个命令用逗号分隔.
set terminal png
set output 'file.png'
plot sin(x)/x, sin(x)
Run Code Online (Sandbox Code Playgroud)
我非常喜欢第二种方式 - 在多画面环境中,这是将多个图形放在同一个图上的唯一方法.如果你有很长的函数可以绘制,你可以使用gnuplot的行继续符号来打破这一行(\在行的末尾 - 在\甚至空白之后都不允许)
plot sin(x)/x with lines linecolor rgb "blue" linetype 7 lineweight 4, \
sin(x), \
cos(x)
Run Code Online (Sandbox Code Playgroud)