@@ -268,36 +268,14 @@ def get_rotate_label(self, text):
268268 return len (text ) > 4
269269
270270 def _get_coord_info (self ):
271- # Get the data-space bounds
272- data_mins , data_maxs = np .array ([
273- self .axes .get_xbound (),
274- self .axes .get_ybound (),
275- self .axes .get_zbound (),
276- ]).T
277-
278- # Transform to scaled space for proper positioning with non-linear scales
279- x_trans = self .axes .xaxis .get_transform ()
280- y_trans = self .axes .yaxis .get_transform ()
281- z_trans = self .axes .zaxis .get_transform ()
282-
283- mins = np .array ([
284- x_trans .transform ([data_mins [0 ]])[0 ],
285- y_trans .transform ([data_mins [1 ]])[0 ],
286- z_trans .transform ([data_mins [2 ]])[0 ],
287- ])
288- maxs = np .array ([
289- x_trans .transform ([data_maxs [0 ]])[0 ],
290- y_trans .transform ([data_maxs [1 ]])[0 ],
291- z_trans .transform ([data_maxs [2 ]])[0 ],
292- ])
293-
294- # Project the bounds along the current position of the cube:
295- # Note: _transformed_cube expects data-space bounds and transforms them
296- # internally
297- bounds = (data_mins [0 ], data_maxs [0 ],
298- data_mins [1 ], data_maxs [1 ],
299- data_mins [2 ], data_maxs [2 ]
300- )
271+ # Get scaled limits directly from the axes helper
272+ xmin , xmax , ymin , ymax , zmin , zmax = self .axes ._get_scaled_limits ()
273+ mins = np .array ([xmin , ymin , zmin ])
274+ maxs = np .array ([xmax , ymax , zmax ])
275+
276+ # Get data-space bounds for _transformed_cube
277+ bounds = (* self .axes .get_xbound (), * self .axes .get_ybound (),
278+ * self .axes .get_zbound ())
301279 bounds_proj = self .axes ._transformed_cube (bounds )
302280
303281 # Determine which one of the parallel planes are higher up:
@@ -484,25 +462,20 @@ def _draw_ticks(self, renderer, edgep1, centers, deltas, highs,
484462
485463 default_label_offset = 8. # A rough estimate
486464 points = deltas_per_point * deltas
465+ # All coordinates below are in scaled space for proper projection
487466 for tick in ticks :
488467 # Get tick line positions
489- # edgep1 is already in scaled space (from _get_coord_info)
490468 pos = edgep1 .copy ()
491- # Transform tick location from data space to scaled space
492- tick_loc_scaled = axis_trans .transform ([tick .get_loc ()])[0 ]
493- pos [index ] = tick_loc_scaled
469+ pos [index ] = axis_trans .transform ([tick .get_loc ()])[0 ]
494470 pos [tickdir ] = out_tickdir
495- # pos is already in scaled space, project directly
496471 x1 , y1 , z1 = proj3d .proj_transform (* pos , self .axes .M )
497472 pos [tickdir ] = in_tickdir
498473 x2 , y2 , z2 = proj3d .proj_transform (* pos , self .axes .M )
499474
500475 # Get position of label
501476 labeldeltas = (tick .get_pad () + default_label_offset ) * points
502-
503477 pos [tickdir ] = edgep1_tickdir
504478 pos = _move_from_center (pos , centers , labeldeltas , self ._axmask ())
505- # pos is already in scaled space, project directly
506479 lx , ly , lz = proj3d .proj_transform (* pos , self .axes .M )
507480
508481 _tick_update_position (tick , (x1 , x2 ), (y1 , y2 ), (lx , ly ))
@@ -528,7 +501,6 @@ def _draw_offset_text(self, renderer, edgep1, edgep2, labeldeltas, centers,
528501
529502 pos = _move_from_center (outeredgep , centers , labeldeltas ,
530503 self ._axmask ())
531- # pos is already in scaled space, project directly
532504 olx , oly , olz = proj3d .proj_transform (* pos , self .axes .M )
533505 self .offsetText .set_text (self .major .formatter .get_offset ())
534506 self .offsetText .set_position ((olx , oly ))
@@ -553,7 +525,6 @@ def _draw_offset_text(self, renderer, edgep1, edgep2, labeldeltas, centers,
553525 # Three-letters (e.g., TFT, FTT) are short-hand for the array of bools
554526 # from the variable 'highs'.
555527 # ---------------------------------------------------------------------
556- # centers is already in scaled space (from _get_coord_info)
557528 centpt = proj3d .proj_transform (* centers , self .axes .M )
558529 if centpt [tickdir ] > pep [tickdir , outerindex ]:
559530 # if FT and if highs has an even number of Trues
@@ -586,10 +557,8 @@ def _draw_labels(self, renderer, edgep1, edgep2, labeldeltas, centers, dx, dy):
586557 label = self ._axinfo ["label" ]
587558
588559 # Draw labels
589- # edgep1, edgep2, and centers are already in scaled space
590560 lxyz = 0.5 * (edgep1 + edgep2 )
591561 lxyz = _move_from_center (lxyz , centers , labeldeltas , self ._axmask ())
592- # lxyz is in scaled space, project directly
593562 tlx , tly , tlz = proj3d .proj_transform (* lxyz , self .axes .M )
594563 self .label .set_position ((tlx , tly ))
595564 if self .get_rotate_label (self .label .get_text ()):
@@ -625,7 +594,7 @@ def draw(self, renderer):
625594
626595 for edgep1 , edgep2 , pos in zip (* self ._get_all_axis_line_edge_points (
627596 minmax , maxmin , self ._tick_position )):
628- # Edge points are already in scaled space (from _get_coord_info)
597+ # Project the edge points along the current position
629598 pep = proj3d ._proj_trans_points ([edgep1 , edgep2 ], self .axes .M )
630599 pep = np .asarray (pep )
631600
@@ -653,7 +622,7 @@ def draw(self, renderer):
653622
654623 for edgep1 , edgep2 , pos in zip (* self ._get_all_axis_line_edge_points (
655624 minmax , maxmin , self ._label_position )):
656- # Edge points are already in scaled space (from _get_coord_info)
625+ # See comments above
657626 pep = proj3d ._proj_trans_points ([edgep1 , edgep2 ], self .axes .M )
658627 pep = np .asarray (pep )
659628 dx , dy = (self .axes .transAxes .transform ([pep [0 :2 , 1 ]]) -
@@ -678,17 +647,13 @@ def draw_grid(self, renderer):
678647 info = self ._axinfo
679648 index = info ["i" ]
680649
681- # For grid lines, we need data-space bounds since Line3DCollection
682- # applies scale transforms in do_3d_projection
683- data_mins , data_maxs = np .array ([
684- self .axes .get_xbound (),
685- self .axes .get_ybound (),
686- self .axes .get_zbound (),
687- ]).T
688-
689- # Get highs from the scaled-space projection
650+ # Grid lines use data-space bounds (Line3DCollection applies transforms)
690651 mins , maxs , tc , highs = self ._get_coord_info ()
691-
652+ xlim , ylim , zlim = (self .axes .get_xbound (),
653+ self .axes .get_ybound (),
654+ self .axes .get_zbound ())
655+ data_mins = np .array ([xlim [0 ], ylim [0 ], zlim [0 ]])
656+ data_maxs = np .array ([xlim [1 ], ylim [1 ], zlim [1 ]])
692657 minmax = np .where (highs , data_maxs , data_mins )
693658 maxmin = np .where (~ highs , data_maxs , data_mins )
694659
0 commit comments