Graph 如何在Gnuplot中绘制带加权边的树/图/网?
我正在gnuplot中绘制一棵树,如这里所讨论的()。但是,我希望包括树的边权重,即对于每条边,我有一个表示边权重的数字(例如10、20、30、40)。下图以红色显示了我想在gnuplot中绘制的边权重(我使用power point添加了这个) 有人能告诉我如何在gnuplot中用权重绘制边吗Graph 如何在Gnuplot中绘制带加权边的树/图/网?,graph,tree,gnuplot,Graph,Tree,Gnuplot,我正在gnuplot中绘制一棵树,如这里所讨论的()。但是,我希望包括树的边权重,即对于每条边,我有一个表示边权重的数字(例如10、20、30、40)。下图以红色显示了我想在gnuplot中绘制的边权重(我使用power point添加了这个) 有人能告诉我如何在gnuplot中用权重绘制边吗 我建议对您在问题中提到的答案稍作修改。假设顶点的坐标存储在文件pnts.dat中,如下所示: 0 5 10 1 20 20 2 15 15 3 30 30 4 40 10
我建议对您在问题中提到的答案稍作修改。假设顶点的坐标存储在文件
pnts.dat
中,如下所示:
0 5 10
1 20 20
2 15 15
3 30 30
4 40 10
这里,第一列记录相应的标签,第二列和第三列分别包含x坐标和y坐标
这些边可以在单独的文件edges.dat
中定义为:
0 1 30 0 1
1 2 40 0 -2
1 4 20 0 1
1 3 10 0 1
这里,前两列包含点索引(它们指的是pnts.dat
的第一列)。第三列记录特定边的权重。最后,最后两列包含生成的关联标签的x、y位移
这样,Gnuplot脚本可以如下所示:
set xr [0:50]
set yr [0:50]
set size square
flePnts = 'pnts.dat'
fleEdges = 'edges.dat'
loadEdges = sprintf('< gawk '' \
FNR==NR{x[$1]=$2;y[$1]=$3;next;} \
{printf "%%f\t%%f\n%%f\t%%f\n\n", x[$1], y[$1], x[$2], y[$2];} \
'' %s %s', flePnts, fleEdges);
loadWeights = sprintf('< gawk '' \
FNR==NR{x[$1]=$2;y[$1]=$3;next;} \
{printf "%%f\t%%f\t%%s\n", (x[$1]+x[$2])/2 + $4, (y[$1]+y[$2])/2 + $5, $3} \
'' %s %s', flePnts, fleEdges);
plot \
loadEdges using 1:2 with lines lc rgb "black" lw 2 notitle, \
flePnts using 2:3:(0.6) with circles fill solid lc rgb "black" notitle, \
flePnts using 2:3:1 with labels tc rgb "white" font "Arial Bold" notitle, \
loadWeights using 1:2:3 with labels tc rgb "red" center font "Arial Bold" notitle
set xr[0:50]
设定年份[0:50]
定格
flePnts='pnts.dat'
fleEdges='edges.dat'
LoadEdge=sprintf(“
loadEdges
命令调用gawk
,以便为所有边生成相应的x/y坐标对(由一个空行分隔)loadWeights
计算每条边的中点,并在这些坐标处放置标签(考虑所需的偏移)此外,如果要在边上添加箭头,必须执行以下步骤:
set style arrow 1 head filled size screen 0.025,10,40 lc rgb "black" lw 2
loadEdges using 1:2:3:4 with vectors arrowstyle 1 notitle, \
set xr [0:50]
set yr [0:50]
set size square
set style arrow 1 head filled size screen 0.025,10,40 lc rgb "black" lw 2
flePnts = 'pnts.dat'
fleEdges = 'edges.dat'
loadEdges = sprintf('< gawk '' \
FNR==NR{x[$1]=$2;y[$1]=$3;next;} \
{printf "%%f\t%%f\t%%f\t%%f\n\n", x[$1], y[$1], (x[$2]-x[$1]), (y[$2]-y[$1]);} \
'' %s %s', flePnts, fleEdges);
loadWeights = sprintf('< gawk '' \
FNR==NR{x[$1]=$2;y[$1]=$3;next;} \
{printf "%%f\t%%f\t%%s\n", (x[$1]+x[$2])/2 + $4, (y[$1]+y[$2])/2 + $5, $3} \
'' %s %s', flePnts, fleEdges);
plot \
loadEdges using 1:2:3:4 with vectors arrowstyle 1 notitle, \
flePnts using 2:3:(0.6) with circles fill solid lc rgb "black" notitle, \
flePnts using 2:3:1 with labels tc rgb "white" font "Arial Bold" notitle, \
loadWeights using 1:2:3 with labels tc rgb "red" center font "Arial Bold" notitle
set xr[0:50]
设定年份[0:50]
定格
设置样式箭头1头部填充尺寸屏幕0.025,10,40 lc rgb“黑色”lw 2
flePnts='pnts.dat'
fleEdges='edges.dat'
LoadEdge=sprintf(“