@@ -1423,6 +1423,42 @@ def _inverse_scale_transform(self, x, y, z):
14231423
14241424 return x_data , y_data , z_data
14251425
1426+ def _set_lims_from_scaled (self , xmin_s , xmax_s , ymin_s , ymax_s ,
1427+ zmin_s , zmax_s ):
1428+ """
1429+ Transform scaled limits back to data space, validate, and set.
1430+
1431+ Takes limits in scaled (transformed) space, converts back to data
1432+ space, applies limit_range_for_scale validation, and sets the axis
1433+ limits.
1434+
1435+ Parameters
1436+ ----------
1437+ xmin_s, xmax_s, ymin_s, ymax_s, zmin_s, zmax_s : float
1438+ Axis limits in scaled space.
1439+ """
1440+ # Transform back to data space
1441+ x_inv = self .xaxis .get_transform ().inverted ()
1442+ y_inv = self .yaxis .get_transform ().inverted ()
1443+ z_inv = self .zaxis .get_transform ().inverted ()
1444+
1445+ xmin , xmax = x_inv .transform ([xmin_s , xmax_s ])
1446+ ymin , ymax = y_inv .transform ([ymin_s , ymax_s ])
1447+ zmin , zmax = z_inv .transform ([zmin_s , zmax_s ])
1448+
1449+ # Validate limits for scale constraints (e.g., positive for log scale)
1450+ xmin , xmax = self .xaxis ._scale .limit_range_for_scale (
1451+ xmin , xmax , self .xy_dataLim .minposx )
1452+ ymin , ymax = self .yaxis ._scale .limit_range_for_scale (
1453+ ymin , ymax , self .xy_dataLim .minposy )
1454+ zmin , zmax = self .zaxis ._scale .limit_range_for_scale (
1455+ zmin , zmax , self .zz_dataLim .minposx )
1456+
1457+ # Set the new axis limits
1458+ self .set_xlim3d (xmin , xmax , auto = None )
1459+ self .set_ylim3d (ymin , ymax , auto = None )
1460+ self .set_zlim3d (zmin , zmax , auto = None )
1461+
14261462 def get_proj (self ):
14271463 """Create the projection matrix from the current viewing position."""
14281464
@@ -1897,37 +1933,10 @@ def drag_pan(self, button, key, x, y):
18971933 dz = (maxz - minz ) * duvw_projected [2 ]
18981934
18991935 # Compute new limits in scaled space
1900- new_xmin_scaled = minx + dx
1901- new_xmax_scaled = maxx + dx
1902- new_ymin_scaled = miny + dy
1903- new_ymax_scaled = maxy + dy
1904- new_zmin_scaled = minz + dz
1905- new_zmax_scaled = maxz + dz
1906-
1907- # Transform back to data space
1908- x_inv = self .xaxis .get_transform ().inverted ()
1909- y_inv = self .yaxis .get_transform ().inverted ()
1910- z_inv = self .zaxis .get_transform ().inverted ()
1911-
1912- new_xmin , new_xmax = x_inv .transform ([new_xmin_scaled , new_xmax_scaled ])
1913- new_ymin , new_ymax = y_inv .transform ([new_ymin_scaled , new_ymax_scaled ])
1914- new_zmin , new_zmax = z_inv .transform ([new_zmin_scaled , new_zmax_scaled ])
1915-
1916- # Validate limits for scale constraints (e.g., positive for log scale)
1917- minpos = self .xy_dataLim .minposx
1918- new_xmin , new_xmax = self .xaxis ._scale .limit_range_for_scale (
1919- new_xmin , new_xmax , minpos )
1920- minpos = self .xy_dataLim .minposy
1921- new_ymin , new_ymax = self .yaxis ._scale .limit_range_for_scale (
1922- new_ymin , new_ymax , minpos )
1923- minpos = self .zz_dataLim .minposx
1924- new_zmin , new_zmax = self .zaxis ._scale .limit_range_for_scale (
1925- new_zmin , new_zmax , minpos )
1926-
1927- # Set the new axis limits
1928- self .set_xlim3d (new_xmin , new_xmax , auto = None )
1929- self .set_ylim3d (new_ymin , new_ymax , auto = None )
1930- self .set_zlim3d (new_zmin , new_zmax , auto = None )
1936+ self ._set_lims_from_scaled (
1937+ minx + dx , maxx + dx ,
1938+ miny + dy , maxy + dy ,
1939+ minz + dz , maxz + dz )
19311940
19321941 def _calc_view_axes (self , eye ):
19331942 """
@@ -2058,38 +2067,11 @@ def _scale_axis_limits(self, scale_x, scale_y, scale_z):
20582067 # Get the axis centers and ranges (in scaled space for non-linear scales)
20592068 cx , cy , cz , dx , dy , dz = self ._get_w_centers_ranges ()
20602069
2061- # Compute new limits in scaled space
2062- new_xmin_scaled = cx - dx * scale_x / 2
2063- new_xmax_scaled = cx + dx * scale_x / 2
2064- new_ymin_scaled = cy - dy * scale_y / 2
2065- new_ymax_scaled = cy + dy * scale_y / 2
2066- new_zmin_scaled = cz - dz * scale_z / 2
2067- new_zmax_scaled = cz + dz * scale_z / 2
2068-
2069- # Transform back to data space
2070- x_inv = self .xaxis .get_transform ().inverted ()
2071- y_inv = self .yaxis .get_transform ().inverted ()
2072- z_inv = self .zaxis .get_transform ().inverted ()
2073-
2074- new_xmin , new_xmax = x_inv .transform ([new_xmin_scaled , new_xmax_scaled ])
2075- new_ymin , new_ymax = y_inv .transform ([new_ymin_scaled , new_ymax_scaled ])
2076- new_zmin , new_zmax = z_inv .transform ([new_zmin_scaled , new_zmax_scaled ])
2077-
2078- # Validate limits for scale constraints (e.g., positive for log scale)
2079- minpos = self .xy_dataLim .minposx
2080- new_xmin , new_xmax = self .xaxis ._scale .limit_range_for_scale (
2081- new_xmin , new_xmax , minpos )
2082- minpos = self .xy_dataLim .minposy
2083- new_ymin , new_ymax = self .yaxis ._scale .limit_range_for_scale (
2084- new_ymin , new_ymax , minpos )
2085- minpos = self .zz_dataLim .minposx
2086- new_zmin , new_zmax = self .zaxis ._scale .limit_range_for_scale (
2087- new_zmin , new_zmax , minpos )
2088-
2089- # Set the new axis limits
2090- self .set_xlim3d (new_xmin , new_xmax , auto = None )
2091- self .set_ylim3d (new_ymin , new_ymax , auto = None )
2092- self .set_zlim3d (new_zmin , new_zmax , auto = None )
2070+ # Compute new limits in scaled space and set
2071+ self ._set_lims_from_scaled (
2072+ cx - dx * scale_x / 2 , cx + dx * scale_x / 2 ,
2073+ cy - dy * scale_y / 2 , cy + dy * scale_y / 2 ,
2074+ cz - dz * scale_z / 2 , cz + dz * scale_z / 2 )
20932075
20942076 def _get_w_centers_ranges (self ):
20952077 """
0 commit comments