8000 ENH: Set the default plotbox aspect to match how renders looked previ… · matplotlib/matplotlib@58e961d · GitHub
[go: up one dir, main page]

Skip to content

Commit 58e961d

Browse files
committed
ENH: Set the default plotbox aspect to match how renders looked previously
This sets it to have a 4:3 aspect ratio, which matches what would result from a typical figure layout
1 parent c765493 commit 58e961d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,9 @@ def get_proj(self):
10271027
point.
10281028
10291029
"""
1030+
# chosen for similarity with the initial view before gh-8896
1031+
pb_aspect = np.array([4, 4, 3]) / 3.5
1032+
10301033
relev, razim = np.pi * self.elev/180, np.pi * self.azim/180
10311034

10321035
xmin, xmax = self.get_xlim3d()
@@ -1036,10 +1039,10 @@ def get_proj(self):
10361039
# transform to uniform world coordinates 0-1.0,0-1.0,0-1.0
10371040
worldM = proj3d.world_transformation(xmin, xmax,
10381041
ymin, ymax,
1039-
zmin, zmax)
1042+
zmin, zmax, pb_aspect=pb_aspect)
10401043

10411044
# look into the middle of the new coordinates
1042-
R = np.array([0.5, 0.5, 0.5])
1045+
R = pb_aspect / 2
10431046

10441047
xp = R[0] + np.cos(razim) * np.cos(relev) * self.dist
10451048
yp = R[1] + np.sin(razim) * np.cos(relev) * self.dist

lib/mpl_toolkits/mplot3d/proj3d.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,20 @@ def mod(v):
8686

8787
def world_transformation(xmin, xmax,
8888
ymin, ymax,
89-
zmin, zmax):
90-
dx, dy, dz = (xmax-xmin), (ymax-ymin), (zmax-zmin)
89+
zmin, zmax, pb_aspect=None):
90+
"""
91+
produce a matrix that scales homogenous coords in the specified ranges
92+
to [0, 1], or [0, pb_aspect[i]] if the plotbox aspect ratio is specified
93+
"""
94+
dx = xmax - xmin
95+
dy = ymax - ymin
96+
dz = zmax - zmin
97+
if pb_aspect is not None:
98+
ax, ay, az = pb_aspect
99+
dx /= ax
100+
dy /= ay
101+
dz /= az
102+
91103
return np.array([[1/dx, 0, 0, -xmin/dx],
92104
[0, 1/dy, 0, -ymin/dy],
93105
[0, 0, 1/dz, -zmin/dz],

0 commit comments

Comments
 (0)
0