2016-11-10 140 views
1

我有一个数据文件“data.txt”,它包含三个维度中几个盒子边框的坐标。每一行代表一个盒子。该文件包含超过100个框。使用gnuplot绘制透明3D盒子

 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)

比我得到这个: enter image description here

但我怎么能在三个维度实现这一目标?我没有找到解决这个问题的办法。

回答

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]) 

结果我得到:

enter image description here

我仍然有兴趣在gnuplot的溶液或Python的一个更快的解决方案。