8000 ENH: Add support for Axes3D.set_pb_aspect · matplotlib/matplotlib@a5a2455 · GitHub
[go: up one dir, main page]

Skip to content

Commit a5a2455

Browse files
eric-wiesertacaswell
authored andcommitted
ENH: Add support for Axes3D.set_pb_aspect
This only keeps the pb related changes from the original commit.
1 parent f18bd14 commit a5a2455

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ def __init__(
9191
self.zz_viewLim = Bbox.unit()
9292
self.xy_dataLim = Bbox.unit()
9393
self.zz_dataLim = Bbox.unit()
94+
if 'pb_aspect' in kwargs:
95+
self.pb_aspect = np.asarray(kwargs['pb_aspect'])
96+
else:
97+
# chosen for similarity with the previous initial view
98+
self.pb_aspect = np.array([4, 4, 3]) / 3.5
9499
# inhibit autoscale_view until the axes are defined
95100
# they can't be defined until Axes.__init__ has been called
96101
self.view_init(self.initial_elev, self.initial_azim)
@@ -348,6 +353,9 @@ def set_anchor(self, anchor, share=False):
348353
ax._anchor = anchor
349354
ax.stale = True
350355

356+
def set_pb_aspect(self, pb_aspect, zoom=1):
357+
self.pb_aspect = pb_aspect * 1.8 * zoom / proj3d.mod(pb_aspect)
358+
351359
def apply_aspect(self, position=None):
352360
if position is None:
353361
position = self.get_position(original=True)
@@ -974,7 +982,12 @@ def set_proj_type(self, proj_type):
974982
def get_proj(self):
975983
"""Create the projection matrix from the current viewing position."""
976984
# chosen for similarity with the initial view before gh-8896
977-
pb_aspect = np.array([4, 4, 3]) / 3.5
985+
986+
# elev stores the elevation angle in the z plane
987+
# azim stores the azimuth angle in the x,y plane
988+
#
989+
# dist is the distance of the eye viewing point from the object
990+
# point.
978991

979992
relev, razim = np.pi * self.elev/180, np.pi * self.azim/180
980993

@@ -985,10 +998,10 @@ def get_proj(self):
985998
# transform to uniform world coordinates 0-1, 0-1, 0-1
986999
worldM = proj3d.world_transformation(xmin, xmax,
9871000
ymin, ymax,
988-
zmin, zmax, pb_aspect=pb_aspect)
1001+
zmin, zmax, pb_aspect=self.pb_aspect)
9891002

9901003
# look into the middle of the new coordinates
991-
R = pb_aspect / 2
1004+
R = self.pb_aspect / 2
9921005

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

0 commit comments

Comments
 (0)
0