gnuplot: draw polygon from data

岁酱吖の 提交于 2019-12-24 14:46:41

问题


How can I plot polygons with data coming from a file? For example if I have a file containing coordinates of the edges of a four-point polygon for each data point, how would I proceed?

e.g. a data file containing

0 0 0 1 1 1 1 0
2 2 2 3 3 3 3 2

should draw two quadratic rectangular wit center at position (0.5,0.5) and (2.5,2.5).


回答1:


Gnuplot doesn't have a dedicated plotting style for plotting arbitrary quadrangles. For that, you must use a different data file format like

0 0
0 1
1 1
1 0
0 0

2 2
2 3
3 3
1 0
0 0

which you can then simply plot with plot 'file.txt' using 1:2 with lines. The empty line between the two parts tells gnuplot to not connect the rectangles.

If you cannot or don't want to change the data file format, you can change the data on-the-fly with an external tool like

plot '< awk ''{print $1,$2,"\n",$3,$4,"\n",$5,$6,"\n",$7,$8,"\n",$1,$2,"\n"}'' rect.txt' with lines


来源:https://stackoverflow.com/questions/29015920/gnuplot-draw-polygon-from-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!