我有一个数据文件“data.txt”,其中包含三维中几个框的边框坐标。每行代表一个盒子。该文件包含100多个框。
x_Min x_Max y_Min y_Max z_Min z_Max
-0.2 0.2 -0.2 0.2 -0.2 0.2
0.2 0.4 -0.2 0.2 -0.2 0.2
....
...
..
现在我想描绘一下。在二维中,使用
非常容易plot "boxes.txt" u 1:2:3:4 w boxxyerrorbars
(x-Value):(y-Value):(Half Width):(Half Height)
。
但我怎样才能在三个方面实现这一目标?我找不到解决这个问题的方法。
答案 0 :(得分:0)
我实际上找到了使用Python和Matplotlib的解决方案。
import numpy as np
import matplotlib.pyplot as plt
import random
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
DIM = 3;
# Unit cube
cube = [[[0.0,1.0],[0.0,0.0],[0.0,0.0]],\
[[0.0,0.0],[0.0,1.0],[0.0,0.0]],\
[[0.0,0.0],[0.0,0.0],[0.0,1.0]],\
[[1.0,1.0],[0.0,1.0],[0.0,0.0]],\
[[1.0,0.0],[1.0,1.0],[0.0,0.0]],\
[[1.0,1.0],[0.0,0.0],[0.0,1.0]],\
[[1.0,1.0],[1.0,1.0],[0.0,1.0]],\
[[0.0,0.0],[1.0,1.0],[0.0,1.0]],\
[[0.0,0.0],[0.0,1.0],[1.0,1.0]],\
[[0.0,1.0],[0.0,0.0],[1.0,1.0]],\
[[1.0,1.0],[0.0,1.0],[1.0,1.0]],\
[[0.0,1.0],[1.0,1.0],[1.0,1.0]]]
# Number of Cubes
numb_Cubes = 5
# Array with positions [x, y, z]
pos = [[0 for x in range(DIM)] for y in range(numb_Cubes)]
for k in range(numb_Cubes):
for d in range(DIM):
pos[k][d] = random.uniform(-1,1)
# Size of cubes
size_of_cubes = [0 for y in range(numb_Cubes)]
for k in range(numb_Cubes):
size_of_cubes[k] = random.random()
# Limits
xmin, xmax = -1, 1
ymin, ymax = -1, 1
zmin, zmax = -1, 1
for n in range(numb_Cubes):
for k in range(len(cube)):
x = np.linspace(cube[k][0][0]*size_of_cubes[n]+pos[n][0], cube[k][0][1]*size_of_cubes[n]+pos[n][0], 2)
y = np.linspace(cube[k][1][0]*size_of_cubes[n]+pos[n][1], cube[k][1][1]*size_of_cubes[n]+pos[n][1], 2)
z = np.linspace(cube[k][2][0]*size_of_cubes[n]+pos[n][2], cube[k][2][1]*size_of_cubes[n]+pos[n][2], 2)
ax.plot(x, y, z, 'black', lw=1)
ax.set_xlim([xmin,xmax])
ax.set_ylim([ymin,ymax])
ax.set_zlim([zmin,ymax])
我得到的结果:
我仍然对gnuplot的解决方案或Python的更快解决方案感兴趣。