2016-11-10 87 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的一個更快的解決方案。