I have seen this thread but my data are a little different. I want to create a 3D plot of multiple files containing x,y,z coordinates and color code each file with a unique color, not each point coordinate
Code thus far:
import meshio
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import glob
import matplotlib.cm as cm
files = sorted(glob.glob('mesh_files/*.vtk'))
mesh = []
fig = plt.figure(figsize = (16, 10))
ax = plt.axes(projection = '3d')
colors = cm.rainbow(np.linspace(0, 1, 16))
for file in files:
mesh.append(meshio.read(file))
x = [m.points[:, 0] for m in mesh]
y = [m.points[:, 1] for m in mesh]
z = [m.points[:, 2] for m in mesh]
for a,b,c,d in zip(x,y,z,colors):
plt.scatter(a,b,c,color=d)
Background
x
, y
and z
are all lists
containing numpy
arrays
<<len(x)
16
<<len(x[0])
99937
<<x[0].shape
(99937,)
<<type(x)
<class 'list'>
<<type(x[0])
<class 'numpy.ndarray'>
I believe the issue is with the colors
and a possible mismatch in sizes
<<len(colors)
16
<<len(colors[0])
4
Error
RuntimeWarning: invalid value encountered in sqrt
EDIT: I can individually call scatter
and manually enter a different color to create the below plot, but this would take forever with 10+ files, so I want it in a loop or function of some sort.
EDIT2: I was able to get this plot, which is nice that the colors are different for each files' data, but the z
scale is too small, compared to the first plot, and it looks like data are missing, it should like like the first plot in terms of z
depth values, but with 16 unique colors as in the second plot. The first plot is only plotting 3 files manually