Matplotlib released a new version 3.1 , the new version brings those new functions and features.
Axes3D.voxels coloring results voxels, voxels () method to change the default parameters shade True. It adjusts the shading according to the direction, which is the same behavior trisurf () and Bar3D () matching parameters.
Sample code:
示例代码: %matplotlib inline import matplotlib.pyplot as plt import numpy as np x, y, z = np.indices((8, 8, 8)) cube1 = (x < 3) & (y < 3) & (z < 3) cube2 = (x >= 5) & (y >= 5) & (z >= 5) link = abs(x - y) + abs(y - z) + abs(z - x) <= 2 voxels = cube1 | cube2 | link colors = np.empty(voxels.shape, dtype=object) colors[link] = 'red' colors[cube1] = 'blue' colors[cube2] = 'green' fig = plt.figure(figsize=plt.figaspect(0.5)) ax, ax_shaded = fig.subplots(1, 2, subplot_kw=dict(projection='3d')) ax.voxels(voxels, facecolors=colors, edgecolor='k', shade=False) ax.set_title("Unshaded") ax_shaded.voxels(voxels, facecolors=colors, edgecolor='k', shade=True) ax_shaded.set_title("Shaded (default)") plt.show()