GNUplot中的多图绘制

6
我想在GNUplot中绘制多个子图或子图。我有两个文件,其中包含两个文件中的x1,y1。我想要在GNUplot中绘制两个图像,就像一个子图一样。假设我有以下两个文件
Plot1
12:14:38 10
12:15:38 11
12:16:38 12
12:17:38 15
和另一个文件
Plot2
12:17:38 15
12:18:38 11
12:19:38 12
12:20:38 15
我想为这两个值生成两个图形。如何使用GNUplot实现呢?请问有人能帮我吗?
谢谢
1个回答

13
如果我理解你的问题,这是基本语法: ```

如果我理解你的问题,这是基本语法:

```
set term png size 600,400
set output 'plot.png'

set multiplot           # engage multiplot mode
set size 1.0,1.0        # sets the size of the first plot
set xdata time          ## these three lines control how gnuplot
set timefmt '%H:%M:%S'  ## reads and writes time-formatted data.
set format x '%H:%M:%S' ##

plot 'data1' u 1:2      # plot the first data set

set size 0.4,0.4        # set the size of the second plot in plot units
set origin 0.15,0.5     # set the origin for the second plot in plot units

plot 'data2' u 1:2      # plot the second data set

这将把第二个数据集绘制为子图。

subfigure plot

为了在一个网格中制作两个图,您可以使用set multiplot layout:
set term png size 600,300
set output 'plot.png'

set multiplot layout 1,2        # engage multiplot mode
#set size 1.0,1.0       # sets the size of the first plot
set xdata time          ## these three lines control how gnuplot
set timefmt '%H:%M:%S'  ## reads and writes time-formatted data.
set format x '%H:%M:%S' ##
set xtics 120           # make time spacing of 2 minutes

plot 'data1' u 1:2      # plot the first data set 

#set size 0.4,0.4       # set the size of the second plot in plot units
#set origin 0.15,0.5    # set the origin for the second plot

plot 'data2' u 1:2      # plot the second data set 
unset multiplot

enter image description here


嗨.. 我想在同一页上放置两个图表,不像你展示的那样。 :( 基本上我想要单页上有两个或四个图表。请问你能告诉我如何做到这一点吗?非常感谢 :) - user1667228
1
@user1667228 -- 这是因为在gnuplot中,它被称为multiplot。要创建一个“网格”图,您只需执行set multiplot layout 2,2(对于2x2网格)。当然,然后您可以使用originsize来调整每个图的位置和大小,就像andyras在此示例中所做的那样,但这很少是必要的。 - mgilson
此外,最好的做法是在结尾处添加 unset multiplot...我不确定现在是否仍然如此,但有些终端以前会在写入任何数据之前等待该命令。 - mgilson
@mgilson 是正确的,使用multiplot layout x,y制作一组子图相当容易。在我的脚本中(我正在使用4.7版本),即使没有unset multiplot也可以正常绘制,但是我同意这是最佳实践,因此我会将其添加进去。 - andyras
@andyras -- 就像我所说的,如果您没有使用unset multiplot,则脚本的行为过去是终端相关的,而不是(必然)gnuplot版本相关的。 - mgilson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接