How to plot images in 3D?

I have a 3-dimensional array where each array element is an RGB value (Hex-codes). This can be thought of as a series of images stacked together in an array. I wanted to display this as a plot (one that is probably slowly and continuously rotating or at least interactive enough to rotate around any axis). Does anyone know how I can plot this in a 3D-style cuboidal plot with a certain level of transparency (So that the edges inside the cube are noticeable)?

Thanks in advance!

HI @Chyavan_MC ,

I am not fully familiar with this process. All I know is that you can use matplotlib for this. Now, with some ChatGPT help, I can also provide this snippet. I have not tested it but it may provide a starting point in your quest:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

Your 3-dimensional array of RGB values

rgb_array = np.array([
[
[‘#FF0000’, ‘#00FF00’, ‘#0000FF’],
[‘#FFFF00’, ‘#FF00FF’, ‘#00FFFF’],
[‘#FFFFFF’, ‘#000000’, ‘#888888’],
],
[
[‘#AA0000’, ‘#00AA00’, ‘#0000AA’],
[‘#AAAA00’, ‘#AA00AA’, ‘#00AAAA’],
[‘#AAAAAA’, ‘#000000’, ‘#555555’],
],
])

Convert hex colors to RGB tuples

def hex_to_rgb(hex_color):
return tuple(int(hex_color.lstrip(‘#’)[i:i+2], 16) for i in (0, 2, 4))

rgb_array = np.vectorize(hex_to_rgb)(rgb_array)

Set up the figure and axis for 3D plotting

fig = plt.figure()
ax = fig.add_subplot(111, projection=‘3d’)

Plot the RGB values in 3D space

for i in range(rgb_array.shape[0]):
for j in range(rgb_array.shape[1]):
for k in range(rgb_array.shape[2]):
r, g, b = rgb_array[i, j, k]
ax.scatter(i, j, k, c=[(r/255, g/255, b/255)], marker=‘o’, depthshade=True)

Set the axis labels

ax.set_xlabel(‘X-axis’)
ax.set_ylabel(‘Y-axis’)
ax.set_zlabel(‘Z-axis’)

Show the plot

plt.show()