How To Plot A 3d Array Like A Image Sequence Of Pixels With Matplotlib
I am trying to display a 3d array - basically, a time-sequence of 2d images - like this : Based on some code I found on SO, my closest solution so far gives me this (using scatter
Solution 1:
Here's the result I'm satisfied with, using voxels as suggested :
%matplotlib qt
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
N = 4
volume = np.random.rand(N, N, N)
filled = np.ones((N, N, N), dtype=np.bool)
# repeating values 3 times for grayscale
colors = np.repeat(volume[:, :, :, np.newaxis], 3, axis=3)
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.voxels(filled, facecolors=colors, edgecolors='k')
plt.show()
Post a Comment for "How To Plot A 3d Array Like A Image Sequence Of Pixels With Matplotlib"