我有一个x,y,z的数据文件,想要使用数据绘制3D圆锥体。我试过splot但它只给出了最后一个圆圈。我的数据文件采用以下格式:
X y z
0 18 18
10 59 59
20 80 80
感谢任何帮助。
提前致谢 -Abhi
答案 0 :(得分: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