ploting i,j,k,r,g,b data from file - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: ploting i,j,k,r,g,b data from file (/thread-19805.html) |
ploting i,j,k,r,g,b data from file - p222 - Jul-15-2019 Dear all, 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! |