For a given 3d *array* plot a plane with *fixed_coord*, using four quadrants.
(ax, array, fixed_coord, cmap)
| 24 | |
| 25 | |
| 26 | def plot_quadrants(ax, array, fixed_coord, cmap): |
| 27 | """For a given 3d *array* plot a plane with *fixed_coord*, using four quadrants.""" |
| 28 | nx, ny, nz = array.shape |
| 29 | index = { |
| 30 | 'x': (nx // 2, slice(None), slice(None)), |
| 31 | 'y': (slice(None), ny // 2, slice(None)), |
| 32 | 'z': (slice(None), slice(None), nz // 2), |
| 33 | }[fixed_coord] |
| 34 | plane_data = array[index] |
| 35 | |
| 36 | n0, n1 = plane_data.shape |
| 37 | quadrants = [ |
| 38 | plane_data[:n0 // 2, :n1 // 2], |
| 39 | plane_data[:n0 // 2, n1 // 2:], |
| 40 | plane_data[n0 // 2:, :n1 // 2], |
| 41 | plane_data[n0 // 2:, n1 // 2:] |
| 42 | ] |
| 43 | |
| 44 | min_val = array.min() |
| 45 | max_val = array.max() |
| 46 | |
| 47 | cmap = plt.get_cmap(cmap) |
| 48 | |
| 49 | for i, quadrant in enumerate(quadrants): |
| 50 | facecolors = cmap((quadrant - min_val) / (max_val - min_val)) |
| 51 | if fixed_coord == 'x': |
| 52 | Y, Z = np.mgrid[0:ny // 2, 0:nz // 2] |
| 53 | X = nx // 2 * np.ones_like(Y) |
| 54 | Y_offset = (i // 2) * ny // 2 |
| 55 | Z_offset = (i % 2) * nz // 2 |
| 56 | ax.plot_surface(X, Y + Y_offset, Z + Z_offset, rstride=1, cstride=1, |
| 57 | facecolors=facecolors, shade=False) |
| 58 | elif fixed_coord == 'y': |
| 59 | X, Z = np.mgrid[0:nx // 2, 0:nz // 2] |
| 60 | Y = ny // 2 * np.ones_like(X) |
| 61 | X_offset = (i // 2) * nx // 2 |
| 62 | Z_offset = (i % 2) * nz // 2 |
| 63 | ax.plot_surface(X + X_offset, Y, Z + Z_offset, rstride=1, cstride=1, |
| 64 | facecolors=facecolors, shade=False) |
| 65 | elif fixed_coord == 'z': |
| 66 | X, Y = np.mgrid[0:nx // 2, 0:ny // 2] |
| 67 | Z = nz // 2 * np.ones_like(X) |
| 68 | X_offset = (i // 2) * nx // 2 |
| 69 | Y_offset = (i % 2) * ny // 2 |
| 70 | ax.plot_surface(X + X_offset, Y + Y_offset, Z, rstride=1, cstride=1, |
| 71 | facecolors=facecolors, shade=False) |
| 72 | |
| 73 | |
| 74 | def figure_3D_array_slices(array, cmap=None): |
no test coverage detected
searching dependent graphs…