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

Appearance settings

Commit 862ed02

Browse filesBrowse files
committed
"What's New": adjustable argument of 3D plots aspect ratio.
1 parent 8941637 commit 862ed02
Copy full SHA for 862ed02

File tree

Expand file treeCollapse file tree

1 file changed

+34
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+34
-0
lines changed
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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='datalim')
30+
# Alternatively: ax.set_aspect(aspects[i], adjustable='box')
31+
# which will change the box aspect ratio instead of axis data limits.
32+
ax.set_title(f"set_aspect('{aspects[i]}')")
33+
34+
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.