Gnuplot:使用可变点类型打印点
我有前两列中的点的x,y值,以及一个数字,该数字表示前三列中的点类型(符号)。列,在一个数据文件中。如何使用不同的符号绘制数据点?不幸的是,没有一种方法(AFAIK)可以使用GNUPLOT从列值自动设置绘制点 但是,可以通过为每个数据系列设置线型,然后根据定义的样式打印值来解决此问题:Gnuplot:使用可变点类型打印点,gnuplot,Gnuplot,我有前两列中的点的x,y值,以及一个数字,该数字表示前三列中的点类型(符号)。列,在一个数据文件中。如何使用不同的符号绘制数据点?不幸的是,没有一种方法(AFAIK)可以使用GNUPLOT从列值自动设置绘制点 但是,可以通过为每个数据系列设置线型,然后根据定义的样式打印值来解决此问题: set style line 1 lc rgb 'red' pt 7 #Circle set style line 2 lc rgb 'blue' pt 5 #Square 请记住,pt后面的数字是点类型 然
set style line 1 lc rgb 'red' pt 7 #Circle
set style line 2 lc rgb 'blue' pt 5 #Square
请记住,pt
后面的数字是点类型
然后,您所要做的就是绘图(假设“data.txt”中的数据是按ColX ColY Col3排序的):
使用这些数据(在标题为“数据”的部分中-还请注意,第3列“符号”已被使用,主要用于说明目的):
在绘图脚本标题中:
set key inside bottom right
set xlabel 'Deflection (m)'
set ylabel 'Force (kN)'
set title 'Some Data'
set style line 1 lc rgb 'red' pt 7
set style line 2 lc rgb 'blue' pt 5
plot "data.txt" using 1:2 title 'Col-Force' with points ls 1, \
"data.txt" using 1:3 title 'Beam-Force' with points ls 2
一个警告当然是您必须重新配置数据输入源
参考资料:
这里有一个可能的解决方案(这是一个简单的外推),只要您没有几十个不同的符号要处理,它就可以工作 假设我想在坐标系中绘制二维点。我只有两个符号,在数据文件的最后一列中,我任意用0和1表示:
0 -0.29450470209121704 1.2279523611068726 1
1 -0.4006965458393097 1.0025811195373535 0
2 -0.7109975814819336 0.9022682905197144 1
3 -0.8540692329406738 1.0190201997756958 1
4 -0.5559651851654053 0.7677079439163208 0
5 -1.1831613779067993 1.5692367553710938 0
6 -0.24254602193832397 0.8055955171585083 0
7 -0.3412654995918274 0.6301406025886536 0
8 -0.25005266070365906 0.7788659334182739 1
9 -0.16853423416614532 0.09659398347139359 1
10 0.169997438788414 0.3473801910877228 0
11 -0.5252010226249695 -0.1398928463459015 0
12 -0.17566296458244324 0.09505800902843475 1
为了实现我想要的,我只需要使用条件来绘制我的文件。使用未定义的值(如1/0
)不会导致绘制给定点:
# Set styles
REG_PTS = 'pointtype 7 pointsize 1.5 linecolor rgb "purple"'
NET_PTS = 'pointtype 4 pointsize 1.5 linecolor rgb "blue"'
set grid
# Plot each category with its own style
plot "data_file" u 2:($4 == 0 ? $3 : 1/0) title "regular" @REG_PTS, \
"data_file" u 2:($4 == 1 ? $3 : 1/0) title "network" @NET_PTS
结果如下:
希望这有帮助
0 -0.29450470209121704 1.2279523611068726 1
1 -0.4006965458393097 1.0025811195373535 0
2 -0.7109975814819336 0.9022682905197144 1
3 -0.8540692329406738 1.0190201997756958 1
4 -0.5559651851654053 0.7677079439163208 0
5 -1.1831613779067993 1.5692367553710938 0
6 -0.24254602193832397 0.8055955171585083 0
7 -0.3412654995918274 0.6301406025886536 0
8 -0.25005266070365906 0.7788659334182739 1
9 -0.16853423416614532 0.09659398347139359 1
10 0.169997438788414 0.3473801910877228 0
11 -0.5252010226249695 -0.1398928463459015 0
12 -0.17566296458244324 0.09505800902843475 1
# Set styles
REG_PTS = 'pointtype 7 pointsize 1.5 linecolor rgb "purple"'
NET_PTS = 'pointtype 4 pointsize 1.5 linecolor rgb "blue"'
set grid
# Plot each category with its own style
plot "data_file" u 2:($4 == 0 ? $3 : 1/0) title "regular" @REG_PTS, \
"data_file" u 2:($4 == 1 ? $3 : 1/0) title "network" @NET_PTS