1"""
2===============================
33D voxel plot of the numpy logo
4===============================
5
6Demonstrates using `.Axes3D.voxels` with uneven coordinates.
7"""
8
9import matplotlib.pyplot as plt
10import numpy as np
11
12
13def explode(data):
14    size = np.array(data.shape)*2
15    data_e = np.zeros(size - 1, dtype=data.dtype)
16    data_e[::2, ::2, ::2] = data
17    return data_e
18
19# build up the numpy logo
20n_voxels = np.zeros((4, 3, 4), dtype=bool)
21n_voxels[0, 0, :] = True
22n_voxels[-1, 0, :] = True
23n_voxels[1, 0, 2] = True
24n_voxels[2, 0, 1] = True
25facecolors = np.where(n_voxels, '#FFD65DC0', '#7A88CCC0')
26edgecolors = np.where(n_voxels, '#BFAB6E', '#7D84A6')
27filled = np.ones(n_voxels.shape)
28
29# upscale the above voxel image, leaving gaps
30filled_2 = explode(filled)
31fcolors_2 = explode(facecolors)
32ecolors_2 = explode(edgecolors)
33
34# Shrink the gaps
35x, y, z = np.indices(np.array(filled_2.shape) + 1).astype(float) // 2
36x[0::2, :, :] += 0.05
37y[:, 0::2, :] += 0.05
38z[:, :, 0::2] += 0.05
39x[1::2, :, :] += 0.95
40y[:, 1::2, :] += 0.95
41z[:, :, 1::2] += 0.95
42
43ax = plt.figure().add_subplot(projection='3d')
44ax.voxels(x, y, z, filled_2, facecolors=fcolors_2, edgecolors=ecolors_2)
45
46plt.show()
47