Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 76ab0f0

Browse files
committed
"What's New" entry for 3D plots aspect adjustable argument.
1 parent 8941637 commit 76ab0f0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff 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()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /