3d grid adapted to non rectangular data in gnuplot

2019-05-31 03:53发布

I would like to plot points in a 3d plot and create a mesh that could handle non rectangular data. To be more specific my data is

data.dat

-1 0 0
-1 1 0
0 -1 0
0 0 0
0 1 0
1 -1 0
1 0 0

and my gnuplot file

plot.plt

set dgrid3d 3,3
splot 'data.dat' w l
pause -1

Unfortunately dgrid3d seems to make my data rectangular and a rectangular grid (actually a square grid) is plotted. Is there a way to plot a restricted envelope of my data ? Ideally I would like to plot the orthogonal convex hull of my set of points.

1条回答
地球回转人心会变
2楼-- · 2019-05-31 04:21

You have a few options for doing something like this -- unfortunately they all require some work on your part.

First, it is important to note that gnuplot can handle non-rectangular meshes for surface plotting (even though you only need a rectangular surface for this example). For surface plotting, the datafile looks like (Notice the blank records):

x11 y11 z11
x21 y21 z21
x31 y31 z31
...

x12 y12 z12
x22 y22 z22
x23 y23 z23
...

It then forms quadrilaterals. In this case, the first quadrilateral would be formed from the points (x11,y11),(x21,y21),(x12,y12),(x22,y22). The second quadrilateral would be formed from (x21,y21),(x31,y31),(x22,y22),(x23,y23) and so forth. So, given your set of points, you can easily create a "rectangular mesh" which will hold all of your datapoints. It won't be evenly spaced, but that's no problem as all. Now we need to figure out how to remove points so that gnuplot won't plot them. This is the "trick". You can mark a particular string as "missing data" in the datafile (set datafile missing "string"). In that case, gnuplot won't plot that point, but it will still keep track of the coordinates of the missing data for the sake of generating the surface.

So at the end of the day, your datafile will look something like:

x11 y11 ?
x21 y21 ?
x31 y31 z31
...

x12 y12 ?
x22 y22 z22
x23 y23 z23
...

and the script to plot it would be:

set datafile missing '?'
set surf
set view map #Not sure about this...depends on the view you want
splot "mydata.dat" u 1:2:3 w lines

If you want gnuplot to compute the "orthogonal convex hull", I think you're out of luck there.

THE EASY WAY

Also note that if you want a solid colored object in 2d space (like the picture on the wikipedia link you posted), this problem becomes significantly easier. If you can create a datafile with just the vertices of the object you want to draw (in order such that (x1,y1) connects to (x2,y2) connects to (x3,y3)...), then you can plot that datafile as:

set fillstyle #However you want the object to appear
plot "datafile.dat" u 1:2 with filledcurves closed
查看更多
登录 后发表回答