0

我在 x、y、z 中有一个数据文件,并想使用该数据绘制一个 3D 圆锥。我试过 splot 但它只给出最后一个点圆。我的数据文件格式如下:

X   y   z 
0  18  18 
10  59  59     
20  80  80 

任何帮助表示赞赏。

在此先感谢-Abhi

4

1 回答 1

1

在这一点上,我认为展示一个简单的脚本可能更容易,该脚本可用于生成 gnuplot 可用于绘制圆锥的格式的数据:

我将使用 python 有两个原因。首先,我非常了解它,其次,它读起来很像伪代码,所以即使你不了解 python,也应该很清楚发生了什么。

import math
h = 2
points_u = map(float,range(-h,h+1)) #[-2.,-1.,0.,1.,2.]

NTHETA = 12    #number of points in theta for the cone
dtheta = 2.*math.pi/NTHETA
points_theta = [dtheta*i for i in range(NTHETA+1)] #list of points in theta

with open('data.txt','w') as fout:  #open an output file for the data
    for theta in points_theta:
        for u in points_u:
            #This is how to plot a cone parametrically
            #Here I unravel the cone into it's x-y-z components
            #The important part is that within the inner loop,
            #we're writing data along a single theta.  In other words,
            #within the inner loop, we write a single straight line which
            #is on the surface of the cone.
            x = (h-u)/h*math.cos(theta)
            y = (h-u)/h*math.sin(theta)
            z = u
            fout.write('%f %f %f\n'%(x,y,z))

        #After the inner loop, you need to insert a blank line to let gnuplot know
        #that the particular "scan" is over and it is supposed to start a new "scan"
        #After all is said and done, gnuplot will connect the points.
        fout.write('\n')

现在这会生成一个数据文件data.txt。要在 gnuplot 中绘制此数据文件,您可以简单地执行以下操作:

set surface
#set hidden3d  #This makes the object "non-transparent"
splot 'data.txt' using 1:2:3 with lines
于 2013-02-06T12:17:41.580 回答