Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jamesbraza opened this issue Jun 11, 2023 · 0 comments
Open

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

jamesbraza opened this issue Jun 11, 2023 · 0 comments

Comments

@jamesbraza
Copy link
Contributor

jamesbraza commented Jun 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants