3

What I would like to have is a plot of rectangular cuboids that are made up of boundary points. Here is a visual of the points, and below it, a simple visual of what I want (but with all rectangles, not just one as drawn).

Is there a simple way to either get wireframe connecting each point, or filled in space between the points so that each set of points looks like a cuboid?

points without lines points with line

I have read this thread, and when I attempt to execute the below code I simply get an empty figure back. However, if I execute the code in the aforementioned thread, I see the same visual that they got. With my code, I simply changed the variables, but aren't seeing anything.

#!/usr/bin/env python3

import meshio
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import numpy as np
import glob
import matplotlib.cm as cm
import matplotlib.ticker as ticker
import pandas as pd
import glob


files = sorted(glob.glob('/path/to/vtk/files/*.vtk'))

fig = plt.figure(figsize=(16,10)) #create figure entity
ax = Axes3D(fig)

colors = iter(cm.rainbow(np.linspace(0, 1, len(files))))

for fyle in files:

    mesh = meshio.read(fyle)
    pts = mesh.points.T

    xmin, xmax = pts[0].min(), pts[0].max()
    ymin, ymax = pts[1].min(), pts[1].max()
    zmin, zmax = pts[2].min(), pts[2].max()

    xc = [xmin, xmax, xmin, xmax, xmax, xmin, xmin, xmax]
    yc = [ymin, ymin, ymax, ymax, ymin, ymin, ymax, ymax]
    zc = [zmin, zmin, zmin, zmin, zmax, zmax, zmax, zmax]

    verts = [list(zip(xc, yc, zc))]
    ax.add_collection3d(Poly3DCollection(verts))

    #coords = np.array((xc, yc, zc))

    #ax.scatter(*coords, c=[next(colors)]) #plot of x,y,z points

plt.show(
William Miller
  • 9,839
  • 3
  • 25
  • 46
NaN
  • 643
  • 1
  • 8
  • 21
  • https://stackoverflow.com/a/57461819/7919597 – Joe Nov 21 '19 at 16:56
  • http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html#mayavi.mlab.triangular_mesh – Joe Nov 21 '19 at 16:57
  • @Joe So is there no other way to plot the surfaces besides creating triangles? Unsure if this solves my problem. – NaN Nov 22 '19 at 13:24
  • I am not sure what you are trying to do. The plot you showed above would look really strange with all cuboids drawn and you would not be able to recognize anything at all. Do you have an example what it should look like in the end? – Joe Nov 22 '19 at 14:55
  • @Joe Sorry for not being clear. I want it sort of like the voxels seen in this thread: https://stackoverflow.com/questions/42611342/representing-voxels-with-matplotlib?noredirect=1&lq=1 or something like these figures but not cubes, I need to use my data which creates elongated cuboids: https://stackoverflow.com/questions/48672663/matplotlib-render-all-internal-voxels-with-alpha – NaN Nov 22 '19 at 14:58
  • I'd build a cuboid using https://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html#mayavi.mlab.triangular_mesh – Joe Nov 22 '19 at 15:01
  • https://stackoverflow.com/questions/30715083/python-plotting-a-wireframe-3d-cuboid – Joe Nov 22 '19 at 15:02
  • https://stackoverflow.com/questions/37388254/basic-3d-voxel-grid-in-mayavi – Joe Nov 22 '19 at 15:02

0 Answers0