|
| 1 | +""" |
| 2 | +====================== |
| 3 | +Primary 3D view planes |
| 4 | +====================== |
| 5 | +
|
| 6 | +This example generates an "unfolded" 3D plot that shows each of the primary 3D |
| 7 | +view planes. The elevation, azimuth, and roll angles required for each view are |
| 8 | +labeled. You could print out this image and fold it into a box where each plane |
| 9 | +forms a side of the box. |
| 10 | +""" |
| 11 | + |
| 12 | +import matplotlib.pyplot as plt |
| 13 | + |
| 14 | + |
| 15 | +def annotate_axes(ax, text, fontsize=18): |
| 16 | + ax.text(x=0.5, y=0.5, z=0.5, s=text, |
| 17 | + va="center", ha="center", fontsize=fontsize, color="black") |
| 18 | + |
| 19 | +# (plane, (elev, azim, roll)) |
| 20 | +views = [('XY', (90, -90, 0)), |
| 21 | + ('XZ', (0, -90, 0)), |
| 22 | + ('YZ', (0, 0, 0)), |
| 23 | + ('-XY', (-90, 90, 0)), |
| 24 | + ('-XZ', (0, 90, 0)), |
| 25 | + ('-YZ', (0, 180, 0))] |
| 26 | + |
| 27 | +layout = [['XY', '.', 'L', '.'], |
| 28 | + ['XZ', 'YZ', '-XZ', '-YZ'], |
| 29 | + ['.', '.', '-XY', '.']] |
| 30 | +fig, axd = plt.subplot_mosaic(layout, subplot_kw={'projection': '3d'}, |
| 31 | + figsize=(12, 8.5)) |
| 32 | +for plane, angles in views: |
| 33 | + axd[plane].set_xlabel('x') |
| 34 | + axd[plane].set_ylabel('y') |
| 35 | + axd[plane].set_zlabel('z') |
| 36 | + axd[plane].set_proj_type('ortho') |
| 37 | + axd[plane].view_init(elev=angles[0], azim=angles[1], roll=angles[2]) |
| 38 | + axd[plane].set_box_aspect(None, zoom=1.25) |
| 39 | + |
| 40 | + label = f'{plane}\n{angles}' |
| 41 | + annotate_axes(axd[plane], label, fontsize=14) |
| 42 | + |
| 43 | +for plane in ('XY', '-XY'): |
| 44 | + axd[plane].set_zticklabels([]) |
| 45 | + axd[plane].set_zlabel('') |
| 46 | +for plane in ('XZ', '-XZ'): |
| 47 | + axd[plane].set_yticklabels([]) |
| 48 | + axd[plane].set_ylabel('') |
| 49 | +for plane in ('YZ', '-YZ'): |
| 50 | + axd[plane].set_xticklabels([]) |
| 51 | + axd[plane].set_xlabel('') |
| 52 | + |
| 53 | +label = 'mplot3d primary view planes\n' + 'ax.view_init(elev, azim, roll)' |
| 54 | +annotate_axes(axd['L'], label, fontsize=18) |
| 55 | +axd['L'].set_axis_off() |
| 56 | + |
| 57 | +plt.show() |
0 commit comments