Python Forum
ploting i,j,k,r,g,b data from file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ploting i,j,k,r,g,b data from file
#1
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![Image: T8Jb7Qm]
Reply


Messages In This Thread
ploting i,j,k,r,g,b data from file - by p222 - Jul-15-2019, 05:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Gridding and ploting Felipe 2 3,586 Jan-19-2017, 04:15 PM
Last Post: Felipe

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020