@@ -1210,7 +1210,7 @@ def __init__(self, x, y, z, dxy=0.8, z0=0, shade=True, lightsource=None, **kws):
1210
1210
self ._lightsource = lightsource
1211
1211
1212
1212
# rectangle polygon vertices
1213
- verts = self ._compute_bar3d_verts ()
1213
+ verts = self ._compute_verts ()
1214
1214
1215
1215
# init Poly3DCollection
1216
1216
if (no_cmap := {'color' , 'facecolor' , 'facecolors' }.intersection (kws )):
@@ -1360,7 +1360,7 @@ def _resolve_colors(self, xyzlist, lightsource):
1360
1360
1361
1361
def _compute_zorder (self ):
1362
1362
# sort by depth (furthest drawn first)
1363
- zorder = camera . distance (self .axes , * self .xy )
1363
+ zorder = camera_distance (self .axes , * self .xy )
1364
1364
zorder = (zorder - zorder .min ()) / zorder .ptp ()
1365
1365
zorder = zorder .ravel () * len (zorder )
1366
1366
panel_order = get_cube_face_zorder (self .axes )
@@ -1516,7 +1516,36 @@ def norm(x):
1516
1516
return colors
1517
1517
1518
1518
1519
- def _compute__bar3d_verts (x , y , z , dx , dy , dz ):
1519
+ def camera_distance (ax , x , y , z = None ):
1520
+ z = np .zeros_like (x ) if z is None else z
1521
+ # camera = xyz(ax)
1522
+ # print(camera)
1523
+ return np .sqrt (np .square (
1524
+ # location of points
1525
+ [x , y , z ] -
1526
+ # camera position in xyz
1527
+ np .array (sph2cart (* _camera_position (ax )), ndmin = 3 ).T
1528
+ ).sum (0 ))
1529
+
1530
+
1531
+ def sph2cart (r , theta , phi ):
1532
+ r_sinθ = r * np .sin (theta )
1533
+ return (r_sinθ * np .cos (phi ),
1534
+ r_sinθ * np .sin (phi ),
1535
+ r * np .cos (theta ))
1536
+
1537
+
1538
+ def _camera_position (ax ):
1539
+ """
1540
+ Returns the camera position for 3D axes in spherical coordinates.
1541
+ """
1542
+ r = np .square (np .max ([ax .get_xlim (),
1543
+ ax .get_ylim ()], 1 )).sum ()
1544
+ theta , phi = np .radians ((90 - ax .elev , ax .azim ))
1545
+ return r , theta , phi
1546
+
1547
+
1548
+ def _compute_bar3d_verts (x , y , z , dx , dy , dz ):
1520
1549
# indexed by [bar, face, vertex, coord]
1521
1550
1522
1551
# handle each coordinate separately
0 commit comments