【问题标题】:plotting lines between points in gnuplot在gnuplot中的点之间绘制线
【发布时间】:2018-11-09 05:26:35
【问题描述】:

我有下一个脚本来绘制文件“puntos”中的点

set title "recorrido vehiculos"
set term png
set output "rutasVehiculos.png"
plot "puntos" u 2:3:(sprintf("%d",$1)) with labels font ",7" point pt 7 offset char 0.5,0.5 notitle

文件“puntos”有下一个格式:

#i x y
1 2.1 3.2
2 0.2 0.3
3 2.9 0.3

在另一个名为“路线”的文件中,我有连接点的路线,例如:

2
1 22 33 20 18 14 8 27 1
1 13 2 17 31 1

路线 1 连接点 1、22、33 等。 路线 2 连接点 1、13、12 等。 有没有办法用 gnuplot 执行此操作?

PS:对不起我的英语

【问题讨论】:

  • 虽然可能,如答案所示,但这不是 gnuplot 的任务。使用 python、perl、you-name-it 中的任何外部脚本来处理您的数据,只将绘图留给 gnuplot

标签: scripting gnuplot


【解决方案1】:

欢迎来到stackoverflow。这是一个有趣的任务。很清楚该怎么做,但是,在我看来,如何做这个 gnuplot 并不是很明显。 以下代码似乎有效,可能还有改进的余地。在 gnuplot 5.2.5 中测试

使用文件puntos.datroutes.dat 测试:

# puntos.dat
#i x y
1 2.1 3.2
2 0.2 0.3
3 2.9 0.3
4 1.3 4.5
5 3.1 2.3
6 1.9 0.7
7 3.6 1.7
8 2.3 1.5
9 1.0 2.0

# routes.dat
2
1 5 7 3 6 2 9
6 8 5 9 4

和代码:

### plot different routes
reset session
set title "recorrido vehiculos"
set term pngcairo
set output "rutasVehiculos.png"

POINTS = "puntos.dat"
ROUTES = "routes.dat"

# load routes file into datablock
set datafile separator "\n"
set table $Routes
    plot ROUTES u (stringcolumn(1)) with table
unset table

# loop routes
set datafile separator whitespace
stats $Routes u 0 nooutput  # get the number of routes
RoutesCount = STATS_records-1
set print $RoutesData
do for [i=1:RoutesCount] {
    # get the points of a single route
    set datafile separator "\n"
    set table $Dummy
       plot ROUTES u (SingleRoute = stringcolumn(1),$1) every ::i::i with table
    unset table
    # create a table of the coordinates of the points of a single route
    set datafile separator whitespace
    do for [j=1:words(SingleRoute)] {
        set table $Dummy2
            plot POINTS u (a=$2,$2):(b=$3,$3) every ::word(SingleRoute,j)-1::word(SingleRoute,j)-1 with table
            print sprintf("%g %s %g %g", j, word(SingleRoute,j), a, b)
        unset table
    }
    print "" # add empty line
}
set print
print sprintf("%g different Routes\n", RoutesCount)
print "RoutesData:"
print $RoutesData
set colorsequence classic 
plot \
    POINTS u 2:3:(sprintf("%d",$1)) with labels font ",7" point pt 7 offset char 0.5,0.5 notitle,\
    for [i=1:RoutesCount] $RoutesData u 3:4 every :::i-1::i-1 w lp lt i title sprintf("Route %g",i)

set output
### end code

结果如下:

【讨论】:

  • 卓越。对于我较旧的 gnuplot 5.0,我不得不将第一个图更改为 plot ROUTES u 1 with table
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-12
  • 1970-01-01
  • 1970-01-01
  • 2011-09-07
  • 2018-12-19
  • 1970-01-01
相关资源
最近更新 更多