This should a straight forward question but I could not find the answer, sorry if the question is a duplicate one. Basically I want to fill Ncell
cells on a 3D grid of Ngrid x Ngrid x Ngrid
. Below I present a MWE where I just scatter plot the centre (or one corner, it does not matter, I can readjust) of each cell.
import numpy as np
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt
Ngrid,Ncell=100,150
xx=np.random.choice(Ngrid,Ncell)
yy=np.random.choice(Ngrid,Ncell)
zz=np.random.choice(Ngrid,Ncell)
%matplotlib widget
fig = plt.figure(figsize = (10, 7))
ax = plt.axes(projection ="3d")
ax.scatter3D(xx,yy,zz,marker='o',alpha=0.5)
Instead of the scatter plot, I need each cell to be filled with a color.
Note that my grid and Ncell
are much larger than the above values (grid = 1000^3 and Ncell=
order 10^5), so an efficient code will be very important.
Thank you in advacne.
CodePudding user response: