Skip to content

[ENH]: nested volumes with one ax.voxels call using alpha #26106

Open
@jamesbraza

Description

@jamesbraza

Problem

Trying to plot a volume inside a volume, with one ax.voxels call, doesn't seem possible:

import matplotlib.pyplot as plt
import numpy as np
from matplotlib import colors

inner = np.zeros((4, 4, 4), dtype=bool)
inner[1:3, 1:3, 1:3] = 1
outer = np.ones((4, 4, 4), dtype=bool)
voxelarray = inner | outer

facecolors = np.empty(voxelarray.shape + (4,), dtype=object)
facecolors[outer] = colors.to_rgba("blue", alpha=0.5)
facecolors[inner] = colors.to_rgba("red")

fig = plt.figure()
ax = fig.add_subplot(projection="3d")
ax.voxels(voxelarray, facecolors=facecolors)
fig.savefig("nested_volumes.png")

nested volumes one voxels call

Nest volumes are possible if invoking ax.voxels twice:

outer_facecolors = np.empty(outer.shape + (4,), dtype=object)
outer_facecolors[outer] = colors.to_rgba("blue", alpha=0.5)
inner_facecolors = np.empty(inner.shape, dtype=object)
inner_facecolors[inner] = "red"

fig = plt.figure()
ax = fig.add_subplot(projection="3d")
ax.voxels(outer, facecolors=outer_facecolors)
ax.voxels(inner, facecolors=inner_facecolors)
ax.set_axis_off()
plt.tight_layout()
fig.savefig("nested_volumes.png", transparent=True)

nested volumes individual voxels call

Proposed solution

It would be nice if matplotlib supported alpha with voxels for nested volumes.

Related: https://stackoverflow.com/questions/48672663/matplotlib-render-all-internal-voxels-with-alpha, which leads to the dupe #9745 that was closed due to inactivity

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions