3d网格适应gnuplot中的非矩形数据 [英] 3d grid adapted to non rectangular data in gnuplot

查看:17
本文介绍了3d网格适应gnuplot中的非矩形数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 3d 图中绘制点并创建一个可以处理非矩形数据的网格.更具体地说,我的数据是

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

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

还有我的 gnuplot 文件

and my gnuplot file

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

不幸的是,dgrid3d 似乎使我的数据变成了矩形,并且绘制了一个矩形网格(实际上是一个方形网格).有没有办法绘制我的数据的受限信封?理想情况下,我想绘制我的一组点的 正交凸包.

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.

推荐答案

你有几个选项来做这样的事情——不幸的是,它们都需要你做一些工作.

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

首先,重要的是要注意 gnuplot 可以处理用于表面绘图的非矩形网格(即使在此示例中您只需要一个矩形表面).对于曲面绘图,数据文件看起来像(注意空白记录):

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
...

然后它形成四边形.在这种情况下,第一个四边形将由点 (x11,y11),(x21,y21),(x12,y12),(x22,y22) 形成.第二个四边形将由 (x21,y21),(x31,y31),(x22,y22),(x23,y23) 等组成.因此,给定您的一组点,您可以轻松创建一个矩形网格"来保存所有数据点.它不会均匀分布,但这完全没有问题.现在我们需要弄清楚如何删除点,以便 gnuplot 不会绘制它们.这就是诀​​窍".您可以在数据文件中将特定字符串标记为缺失数据"(set datafile missing string").在这种情况下,gnuplot 不会绘制该点,但它仍会跟踪丢失数据的坐标以生成表面.

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
...

绘制它的脚本是:

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

如果你想让 gnuplot 计算正交凸包",我认为你不走运.

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

简单的方法

还请注意,如果您想要在 2d 空间中使用纯色对象(如您发布的 wikipedia 链接上的图片),则此问题会变得容易得多.如果您可以仅使用要绘制的对象的顶点创建一个数据文件(以便 (x1,y1) 连接到 (x2,y2) 连接到 (x3,y3)...),那么您可以绘制该数据文件为:

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

这篇关于3d网格适应gnuplot中的非矩形数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆