如何在 gnuplot 中使用不同的点类型划线?
我正在尝试用虚线绘制数据文件。以下是一些值:
2001 dic 21 5,9 9,2 3,8 0,2
2001 dic 22 6,8 8,7 4,8 4,2
2001 dic 23 6,3 8,1 6,5 6,8
2001 dic 24 3,1 4,1 3
2001 dic 25 -1, 3,5 -5
2001 dic 26 4,5 8 0,8 14,8
2001 dic 27 4 7 2,7 0,2
2001 dic 28 0,1 3,4 -3,5
2001 dic 29 7 10,7 2,9 6,2
2001 dic 30 11,2 12,9 8 1,4
2001 dic 31 5,2 6,3 5 3,4
2002 gen 1 2,9 6,9 0,8
2002 gen 2 -0,8 5,4 -5,4
2002 gen 3 2,0 8,0 -1,8
2002 gen 4 2,0 5,2 0,1
2002 gen 5 -0,8 5,5 -5,2
2002 gen 6 0,3 6,7 -4,3
2002 gen 7 0,5 5,6 -3,4
2002 gen 8 1,2 7,9 -3,3
2002 gen 9 1,9 8,4 -2,8
2002 gen 10 1,8 8,1 -2,7
2002 gen 11 3,6 7,7 -0,7
2002 gen 12 6,0 10,2 3,5
为了避免与其他图表混淆,我应该绘制的不是精确的虚线而是珠子(“°”)。 Gnuplot 只允许使用“.-_”来表示用户定义的虚线。使用用户定义的线点进行绘图可能是解决方案,但是您有线条和珠子,而不仅仅是“珠子”,如下所示(查看中间的图):
仅使用 user- 进行绘图定义点珠子之间留下很多空白空间。因此,我尝试创建一个新的数据文件,其中包含通过原始数据文件值的线性插值获得的更多值,以填充这些空白空间(前三列是“2022 年 2 月 28 日”等类型的时间戳数据):
set table $Temp
plot "datafile.csv" u 1:4:5:6:7 skip 15 w table
unset table
set print $Temp2 #this file is like $Temp with lots of values added by interpolation
do for [i = 1:|$Temp|-1] {
print $Temp[i:($1)],$Temp[i:($4)]
do for [j = 1,10] { print $Temp[i:($1)]+($Temp[i+1:($1)]-$Temp[i:($1)])*j/11), $Temp[i:($4)]+($Temp[i+1:($4)]-$Temp[i:($4)])*j/11) }
}
print $Temp[|$Temp|:($1)],$Temp[|$Temp|:($4)]
set print
显然这不起作用,因为我没有正确处理 $Temp 文件的列。在 gnuplot 手册中查找“数组”没有提供任何提示。最后,生成的文件应该用点 pt“°”绘制。
I'm trying to plot a datafile with dashed lines. Here are some of the values:
2001 dic 21 5,9 9,2 3,8 0,2
2001 dic 22 6,8 8,7 4,8 4,2
2001 dic 23 6,3 8,1 6,5 6,8
2001 dic 24 3,1 4,1 3
2001 dic 25 -1, 3,5 -5
2001 dic 26 4,5 8 0,8 14,8
2001 dic 27 4 7 2,7 0,2
2001 dic 28 0,1 3,4 -3,5
2001 dic 29 7 10,7 2,9 6,2
2001 dic 30 11,2 12,9 8 1,4
2001 dic 31 5,2 6,3 5 3,4
2002 gen 1 2,9 6,9 0,8
2002 gen 2 -0,8 5,4 -5,4
2002 gen 3 2,0 8,0 -1,8
2002 gen 4 2,0 5,2 0,1
2002 gen 5 -0,8 5,5 -5,2
2002 gen 6 0,3 6,7 -4,3
2002 gen 7 0,5 5,6 -3,4
2002 gen 8 1,2 7,9 -3,3
2002 gen 9 1,9 8,4 -2,8
2002 gen 10 1,8 8,1 -2,7
2002 gen 11 3,6 7,7 -0,7
2002 gen 12 6,0 10,2 3,5
For avoiding confusion with other graphs, I should plot not exactly dashed lines but beads ('°'). Gnuplot permits only ".-_" for user-defined dashed lines. Plotting with user-defined linespoints could be the solution but there you have lines and beads, not just 'beads', something like this (look at the plot in the middle):
To plot with just user-defined points leaves a lot of empty spaces between the beads. So I'm trying to create a new datafile with many more values obtained by linear interpolation of the primitive datafile values, to fill those empty spaces (the first three columns are timestamp data of the kind '2022 feb 28' and the like):
set table $Temp
plot "datafile.csv" u 1:4:5:6:7 skip 15 w table
unset table
set print $Temp2 #this file is like $Temp with lots of values added by interpolation
do for [i = 1:|$Temp|-1] {
print $Temp[i:($1)],$Temp[i:($4)]
do for [j = 1,10] { print $Temp[i:($1)]+($Temp[i+1:($1)]-$Temp[i:($1)])*j/11), $Temp[i:($4)]+($Temp[i+1:($4)]-$Temp[i:($4)])*j/11) }
}
print $Temp[|$Temp|:($1)],$Temp[|$Temp|:($4)]
set print
Obviously this does not work since I'm not handling the columns of the $Temp file correctly. Looking up "arrays" in gnuplot manual does not provide any hint. At the end, the resulting file should be plotted with points pt "°".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:由于我将问题标题更改为“...不同点类型...”,我应该展示如何使用多列和不同的点类型来完成此操作。
多列的数据沿着路径插入,并作为(子)块附加到数据块
$DashMultipleCols
中,稍后可以通过index
对其进行寻址。我让你来决定是实线/虚线/点线还是加号/圆形/三角形更容易区分。以下示例创建一个沿给定路径具有等距点的数据块。
为了说明,一些随机测试数据是使用 1 个 x 列和 3 个 y 列创建的
为了进行比较,第一个图表包含实线、虚线和点线。在我看来,这些线条可以很好地区分,但你要求用符号“划线”。
对于第二个图,第 2、3、4 列的数据分别用点类型 1、6、8 进行“虚线”显示。
符号之间的距离由变量设置,此处:
Dist = 8
为了获得视觉上均匀的分布,使用从 x,y 到像素坐标的坐标转换以及反向转换。为此,使用 gnuplot 变量 GPVAL...,这些变量在绘图后可用。这就是为什么有必要绘制两次。可以删除命令
pause -1
。这适用于线性轴(需要调整对数轴)
您的数据是时间数据。代码需要做相应的调整。
代码:(使用wxt终端测试)
结果:
添加: 适合时间格式的
代码gnuplot 中的时间只不过是自 1970 年 1 月 1 日 00:00:00 以来经过的秒数。如果您在 gnuplot 控制台中输入
print time(0)
(即当前时间),您将得到类似 1646757721 的信息,因此从那时到今天已经过去了大约 16 亿秒。与上面的代码相比,主要区别和需要记住的事情:
myTimeFmt = "%Y %b %d"
plot $Data u (timecolumn(1,myTimeFmt)):4 w l
$LaA
) 您还必须使用第 4,5,6 列和timecolumn()
,即plot x1=y1=NaN $Data u ( x0=x1,x1=XtoPix(timecolumn(colX,myTimeFmt)),x0)
$DashSingleCol
您必须强制使用格式时间为"%.0f"
即print sprintf("%.0f %g", PixToX(X0(idx)+(R-L0)*cos(SegAngle(idx) )))
否则,使用"%g"
gnuplot 会写出一个带有指数但只有 6 位数字的浮点数,例如1.64676e+09
这对于绘制$DashMultipleCols
来说是不需要的截断或舍入,u 1:2
因为时间已经到了。以秒为单位,并且不必通过timecolumn()
进行更改。我希望这些额外的代码和解释将帮助您用不同的符号“破折号”您的数据。
代码:
结果:
Edit: Since I changed the question title to "...different pointtypes...", I should show how to do it with multiple columns and different pointtypes.
The data of multiple columns is interpolated along the path and appended to the datablock
$DashMultipleCols
as (sub-)blocks which can later be addressed viaindex
. I leave it up to you to decide whether solid/dash/dotted or plus/circle/triangle is easier to distinguish.The following example creates a datablock with equidistant points along a given path.
for illustration some random test data is created with 1 x-column and 3 y-columns
for comparison the first graph is with solid, dashed and dotted lines. To my opinion the lines can be well distinguished, but you asked for "dashing" with a symbol.
for the second plot the data of columns 2,3,4 is "dashed" with the pointtypes 1,6,8, respectively.
the distance between the symbols is set by a variable, here:
Dist = 8
in order to get a visually equal distribution, coordinate conversions from x,y to pixel coordinates and reverse are used. For this, the gnuplot variables GPVAL... are used which are available after plotting. That's why it is necessary to plot twice. The command
pause -1
can be removed.this works for linear axes (would need adjustment for logarithmic axes)
Your data is timedata. The code needs to be adjusted accordingly.
Code: (tested with wxt terminal)
Result:
Addition: Code adapted for time format
The time in gnuplot is nothing else than seconds passed since Jan 1st, 1970 00:00:00. If you enter in the gnuplot console
print time(0)
(which is the current time) you will get something like 1646757721, so about 1.6 billion seconds have passed since then until today.The main differences and things to keep in mind compared to the above code:
myTimeFmt = "%Y %b %d"
plot $Data u (timecolumn(1,myTimeFmt)):4 w l
$LaA
) you also have to use columns 4,5,6 andtimecolumn()
as well, i.e.plot x1=y1=NaN $Data u (x0=x1,x1=XtoPix(timecolumn(colX,myTimeFmt)),x0)
$DashSingleCol
you have to force the format for the time to be"%.0f"
i.e.print sprintf("%.0f %g", PixToX(X0(idx)+(R-L0)*cos(SegAngle(idx)))
. Otherwise, with"%g"
gnuplot would write a floating point number with exponent but only 6 digits, e.g.1.64676e+09
which would be unwanted truncation or rounding.$DashMultipleCols
you can simply useu 1:2
because the time is already in seconds and does not have to be changes viatimecolumn()
.I hope this additional code and the explanations will help you to "dash" your data with different symbols.
Code:
Result:
设置xdata时间
就可以了。set timefmt myTimeFmt
仅适用于设置具有相同时间日期格式的 xrange 和 xtics。然后,在绘图之前,必须根据要绘图的文件的时间日期格式(即 $DashMultipleCols)修改set timefmt
,在本例中为秒;因此设置timefmt“%s”
。set xdata time
is just fine.set timefmt myTimeFmt
is ok ONLY for setting xrange and xtics with that same timedate format. Then, right before plotting,set timefmt
must be modified according to the timedate format of the file to plot (that is, $DashMultipleCols), which in this case is seconds; thereforeset timefmt "%s"
.