Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c3e7c48

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 4479a0f commit c3e7c48

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,9 @@ def get_proj(self):
964964
965965
dist is the distance of the eye viewing point from the object point.
966966
"""
967+
# chosen for similarity with the initial view before gh-8896
968+
pb_aspect = np.array([4, 4, 3]) / 3.5
969+
967970
relev, razim = np.pi * self.elev/180, np.pi * self.azim/180
968971

969972
xmin, xmax = self.get_xlim3d()
@@ -973,10 +976,10 @@ def get_proj(self):
973976
# transform to uniform world coordinates 0-1, 0-1, 0-1
974977
worldM = proj3d.world_transformation(xmin, xmax,
975978
ymin, ymax,
976-
zmin, zmax)
979+
zmin, zmax, pb_aspect=pb_aspect)
977980

978981
# look into the middle of the new coordinates
979-
R = np.array([0.5, 0.5, 0.5])
982+
R = pb_aspect / 2
980983

981984
xp = R[0] + np.cos(razim) * np.cos(relev) * self.dist
982985
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
@@ -30,8 +30,20 @@ def _line2d_seg_dist(p1, p2, p0):
3030

3131
def world_transformation(xmin, xmax,
3232
ymin, ymax,
33-
zmin, zmax):
34-
dx, dy, dz = (xmax-xmin), (ymax-ymin), (zmax-zmin)
33+
zmin, zmax, pb_aspect=None):
34+
"""
35+
produce a matrix that scales homogenous coords in the specified ranges
36+
to [0, 1], or [0, pb_aspect[i]] if the plotbox aspect ratio is specified
37+
"""
38+
dx = xmax - xmin
39+
dy = ymax - ymin
40+
dz = zmax - zmin
41+
if pb_aspect is not None:
42+
ax, ay, az = pb_aspect
43+
dx /= ax
44+
dy /= ay
45+
dz /= az
46+
3547
return np.array([[1/dx, 0, 0, -xmin/dx],
3648
[0, 1/dy, 0, -ymin/dy],
3749
[0, 0, 1/dz, -zmin/dz],

0 commit comments

Comments
 (0)