Gnuplot将每一个点连接在一起

问题描述 投票:4回答:1

我正在绘制gnuplot中的数据,如下所示:

set terminal pdf
set output "Planck.pdf"
plot "CalculatedValues.dat" u 1:2 t "Dawn" pt 1 ps .1 with lines

但我的输出最终看起来像一个纱线雕塑,

enter image description here

我希望输出看起来像,但是线图而不是散点图。

enter image description here

我究竟做错了什么?

这是一些数据:

13.4904 3.13714e+07     3.91106e+07
11.3872 4.64475e+07     5.96647e+07
18.0928 1.40999e+07     1.69117e+07
13.3284 3.23223e+07     4.03737e+07
1.3264  3309.46 24012.2
0.323113        5.16869e-25     1.764e-21
10.6252 5.35423e+07     6.97629e+07

它的标签分隔,新线分开

gnuplot
1个回答
4
投票

问题在于您的积分顺序。 Gnuplot会用文件连接文件中的连续点。如果这些点是基于x轴值(在这种情况下是第一列)的顺序,那么你将得到你所追求的。如果他们不是,你会得到像你看到的奇怪的结果。

未分类的数据

13.4904   3.13714e+07   3.91106e+07
11.3872   4.64475e+07   5.96647e+07
18.0928   1.40999e+07   1.69117e+07
13.3284   3.23223e+07   4.03737e+07
1.3264    3309.46       24012.2
0.323113  5.16869e-25   1.764e-21
10.6252   5.35423e+07   6.97629e+07

plot datafile u 1:2 w linespoints pt 7产生以下†

enter image description here

这里对点进行编号以显示它们的绘制顺序。我们可以看到连接在数据文件中连续出现的点。

排序数据

0.323113   5.16869e-25   1.764e-21
1.3264     3309.46       24012.2
10.6252    5.35423e+07   6.97629e+07
11.3872    4.64475e+07   5.96647e+07
13.3284    3.23223e+07   4.03737e+07
13.4904    3.13714e+07   3.91106e+07
18.0928    1.40999e+07   1.69117e+07

plot datafile u 1:2 w linespoints pt 7产生以下†

enter image description here

在这里,我们看到绘制了相同的点,但顺序不同。同样,连续点被连接,但是以递增的顺序完成,因为数据在这种情况下被分类。


The solution is to sort your data first. Either have the program generating the data sort it during production, or use an external program to sort it before plotting.

如果第一列中的值是唯一的,则其中一个平滑选项可与原始未排序数据一起使用。例如,

plot datafile u 1:2 smooth unique w linespoints pt 7

将产生与使用排序数据绘图相同的结果。‡这是因为平滑唯一选项首先按x列对数据进行排序。 y值被所有y值的平均值替换为相应的x值。如果x值是唯一的,则表示原始数据仅按排序顺序保留。


The plot command shown will only draw the lines. To get the numerical labels as well, we use
plot datafile u 1:2 w linespoints pt 7, \
           "" u 1:2:(sprintf("%d",$0+1)) w labels offset 0,graph 0.05

在每个点坐标处绘制标签,向上移动图形范围的5%(使用图形坐标系)。由于0伪列(行号)是基于0的,我们添加以生成标签,我们将给出基于1的标签。

‡如果我们想在这里标记点,我们必须使用set table来捕获平滑数据,然后绘制数据。干

set table "tempfile"
plot datafile u 1:2 smooth unique
unset table
plot "tempfile" u 1:2 w linespoints pt 7, \
             "" u 1:2:(sprintf("%d",$0+1)) w labels offset 0,graph 0.05

将完全生成上面的排序图。数据被捕获到临时文件,第一个绘图命令只生成点。以下plot命令将现在排序的数据与标签一起绘制。这允许gnuplot自己完成所有排序,但同样,这只有在第一列中的值是唯一的时才有效。

© www.soinside.com 2019 - 2024. All rights reserved.