-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathwhats_new-4.py
More file actions
29 lines (23 loc) · 894 Bytes
/
whats_new-4.py
File metadata and controls
29 lines (23 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import matplotlib.pyplot as plt
import numpy as np
# prepare some coordinates
x, y, z = np.indices((8, 8, 8))
# draw cuboids in the top left and bottom right corners, and a link between them
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
# combine the objects into a single boolean array
voxels = cube1 | cube2 | link
# set the colors of each object
colors = np.empty(voxels.shape, dtype=object)
colors[link] = 'red'
colors[cube1] = 'blue'
colors[cube2] = 'green'
# and plot everything
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()