@@ -1166,7 +1166,7 @@ def __init__(self, x, y, z, dxy=0.8, z0=0, shade=True, lightsource=None, **kws):
1166
1166
self ._lightsource = lightsource
1167
1167
1168
1168
# rectangle polygon vertices
1169
- verts = self ._compute_bar3d_verts ()
1169
+ verts = self ._compute_verts ()
1170
1170
1171
1171
# init Poly3DCollection
1172
1172
if (no_cmap := {'color' , 'facecolor' , 'facecolors' }.intersection (kws )):
@@ -1316,7 +1316,7 @@ def _resolve_colors(self, xyzlist, lightsource):
1316
1316
1317
1317
def _compute_zorder (self ):
1318
1318
# sort by depth (furthest drawn first)
1319
- zorder = camera . distance (self .axes , * self .xy )
1319
+ zorder = camera_distance (self .axes , * self .xy )
1320
1320
zorder = (zorder - zorder .min ()) / zorder .ptp ()
1321
1321
zorder = zorder .ravel () * len (zorder )
1322
1322
panel_order = get_cube_face_zorder (self .axes )
@@ -1470,7 +1470,36 @@ def norm(x):
1470
1470
return colors
1471
1471
1472
1472
1473
- def _compute__bar3d_verts (x , y , z , dx , dy , dz ):
1473
+ def camera_distance (ax , x , y , z = None ):
1474
+ z = np .zeros_like (x ) if z is None else z
1475
+ # camera = xyz(ax)
1476
+ # print(camera)
1477
+ return np .sqrt (np .square (
1478
+ # location of points
1479
+ [x , y , z ] -
1480
+ # camera position in xyz
1481
+ np .array (sph2cart (* _camera_position (ax )), ndmin = 3 ).T
1482
+ ).sum (0 ))
1483
+
1484
+
1485
+ def sph2cart (r , theta , phi ):
1486
+ r_sinθ = r * np .sin (theta )
1487
+ return (r_sinθ * np .cos (phi ),
1488
+ r_sinθ * np .sin (phi ),
1489
+ r * np .cos (theta ))
1490
+
1491
+
1492
+ def _camera_position (ax ):
1493
+ """
1494
+ Returns the camera position for 3D axes in spherical coordinates.
1495
+ """
1496
+ r = np .square (np .max ([ax .get_xlim (),
1497
+ ax .get_ylim ()], 1 )).sum ()
1498
+ theta , phi = np .radians ((90 - ax .elev , ax .azim ))
1499
+ return r , theta , phi
1500
+
1501
+
1502
+ def _compute_bar3d_verts (x , y , z , dx , dy , dz ):
1474
1503
# indexed by [bar, face, vertex, coord]
1475
1504
1476
1505
# handle each coordinate separately
0 commit comments