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 plot and big squared markers) :
but the squared markers are not aligned along the 3 axes. So I am asking:
- if their is a workaround to make the markers aligned (and still as the plot is rotated)
- or/and if their is prettier way ?
Here's the code :
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
N = 8
volume = np.random.rand(N, N, N)
x = np.arange(volume.shape[0])[:, None, None]
y = np.arange(volume.shape[1])[None, :, None]
z = np.arange(volume.shape[2])[None, None, :]
x, y, z = np.broadcast_arrays(x, y, z)
c = np.tile(volume.ravel()[:, None], [1, 3])
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.scatter(x.ravel(),
y.ravel(),
z.ravel(),
c=c,
s=500, # marker's size
marker="s") # squared markers