| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,32 @@ | |||
| 1 | + `adjustable` keyword argument for setting equal aspect ratios in 3D | ||
| 2 | + ------------------------------------------------------------------- | ||
| 3 | + | ||
| 4 | + While setting equal aspect ratios for 3D plots, users can choose to modify | ||
| 5 | + either the data limits or the bounding box. | ||
| 6 | + | ||
| 7 | + .. plot:: | ||
| 8 | + :include-source: true | ||
| 9 | + | ||
| 10 | + import matplotlib.pyplot as plt | ||
| 11 | + import numpy as np | ||
| 12 | + from itertools import combinations, product | ||
| 13 | + | ||
| 14 | + aspects = ('auto', 'equal', 'equalxy', 'equalyz', 'equalxz') | ||
| 15 | + fig, axs = plt.subplots(1, len(aspects), subplot_kw={'projection': '3d'}, | ||
| 16 | + figsize=(12, 6)) | ||
| 17 | + | ||
| 18 | + # Draw rectangular cuboid with side lengths [4, 3, 5] | ||
| 19 | + r = [0, 1] | ||
| 20 | + scale = np.array([4, 3, 5]) | ||
| 21 | + pts = combinations(np.array(list(product(r, r, r))), 2) | ||
| 22 | + for start, end in pts: | ||
| 23 | + if np.sum(np.abs(start - end)) == r[1] - r[0]: | ||
| 24 | + for ax in axs: | ||
| 25 | + ax.plot3D(*zip(start*scale, end*scale), color='C0') | ||
| 26 | + | ||
| 27 | + # Set the aspect ratios | ||
| 28 | + for i, ax in enumerate(axs): | ||
| 29 | + ax.set_aspect(aspects[i], adjustable='box') | ||
| 30 | + ax.set_title(f"set_aspect('{aspects[i]}')") | ||
| 31 | + | ||
| 32 | + plt.show() | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments