使用gnuplot打印透明的三维框

使用gnuplot打印透明的三维框,gnuplot,visualization,Gnuplot,Visualization,我有一个数据文件“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

我有一个数据文件“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值):(y值):(半宽):(半高)

然后我得到这个:


但我怎样才能在三个方面做到这一点呢?我没有找到这个问题的任何解决方案。

我实际上找到了一个使用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的更快的解决方案感兴趣。

我实际上找到了一个使用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的更快的解决方案感兴趣