Skip to content Skip to sidebar Skip to footer

How To Scale The Voxel-dimensions With Matplotlib?

Want to scale the voxel-dimensions with Matplotlib. How can I do this? import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure(

Solution 1:

You can pass custom coordinates to the voxels function: API reference.

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.gca(projection='3d')
# Make grid
test2 = np.zeros((6, 6, 6))
# Activate single Voxel
test2[1, 0, 4] = True# Custom coordinates for grid
x,y,z = np.indices((7,7,7))/2# Pass the custom coordinates as extra arguments
ax.voxels(x, y, z, test2, edgecolor="k")
ax.set_xlabel('0 - Dim')
ax.set_ylabel('1 - Dim')
ax.set_zlabel('2 - Dim')

plt.show()

Which would yield:

enter image description here

Solution 2:

voxels accept the coordinates of the grid onto which to place the voxels.

voxels([x, y, z, ]/, filled, ...)

x, y, z : 3D np.array, optional The coordinates of the corners of the voxels. This should broadcast to a shape one larger in every dimension than the shape of filled. These can be used to plot non-cubic voxels.

If not specified, defaults to increasing integers along each axis, like those returned by indices(). As indicated by the / in the function signature, these arguments can only be passed positionally.

In this case,

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.gca(projection='3d')
# Make grid
voxels = np.zeros((6, 6, 6))
# Activate single Voxel
voxels[1, 0, 4] = True

x,y,z = np.indices(np.array(voxels.shape)+1)

ax.voxels(x*0.5, y, z, voxels, edgecolor="k")
ax.set_xlabel('0 - Dim')
ax.set_ylabel('1 - Dim')
ax.set_zlabel('2 - Dim')

plt.show()

Post a Comment for "How To Scale The Voxel-dimensions With Matplotlib?"