Reputation: 35
I have 3D array normalized (between 0 and 1) data, I would like view it 3D format in python like this, with the colors matching the values in the array.
Upvotes: 1
Views: 1200
Reputation: 260300
You could use matplotlib.pyplot.scatter
with a 3D projection:
import numpy as np
import matplotlib.pyplot as plt
a = np.random.random(size=(20, 10, 5))
ax = plt.subplot(projection='3d')
grid = np.meshgrid(np.arange(a.shape[2]),
np.arange(a.shape[1]),
np.arange(a.shape[0]))
x = ax.scatter(*grid, c=a)
plt.colorbar(x)
You could use matplotlib.pyplot.imshow
:
import numpy as np
import matplotlib.pyplot as plt
a = np.random.random(size=(50,100))
plt.imshow(a, vmin=0, vmax=1)
plt.colorbar()
output:
Upvotes: 1