Jul-15-2019, 05:31 PM
(This post was last modified: Jul-16-2019, 01:15 AM by Larz60+. Edited 2 times in total.)

Dear all,

I have this code working, which is giving me what I'm showing in the picture:

- make a 10x10x10 cube instead of 3x3x3.

- for the 10x10x10 cube, read the color in rgb from a file.

I would really appreciate if somebody can help me out with this, thank you!

Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.

I have this code working, which is giving me what I'm showing in the picture:

#!/usr/bin/env python import matplotlib.pyplot as plt[img]https://ibb.co/T8Jb7Qm[/img] import numpy as np # This import registers the 3D projection, but is otherwise unused. from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import def make_ax(grid=False): fig = plt.figure() ax = fig.gca(projection='3d') ax.set_xlabel("x") ax.set_ylabel("y") ax.set_zlabel("z") ax.grid(grid) return ax def explode(data): shape_arr = np.array(data.shape) size = shape_arr[:3]*2 - 1 exploded = np.zeros(np.concatenate([size, shape_arr[3:]]), dtype=data.dtype) exploded[::2, ::2, ::2] = data return exploded def expand_coordinates(indices): x, y, z = indices x[1::2, :, :] += 1 y[:, 1::2, :] += 1 z[:, :, 1::2] += 1 return x, y, z ax = make_ax() colors = np.array([[['#ff0000ff']*3]*3]*3) colors[1,1,1] = '#ff0000ff' colors = explode(colors) filled = explode(np.ones((3, 3, 3))) x, y, z = expand_coordinates(np.indices(np.array(filled.shape) + 1)) ax.voxels(x, y, z, filled, facecolors=colors, edgecolors='gray') plt.show()Do you know how if I want to:

- make a 10x10x10 cube instead of 3x3x3.

- for the 10x10x10 cube, read the color in rgb from a file.

I would really appreciate if somebody can help me out with this, thank you!

**Larz60+**wrote Jul-16-2019, 01:15 AM:Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.