@@ -38,9 +38,10 @@ def __init__(self, *, ax: MplAxes, figure=None) -> None:
3838 self .collections = []
3939 self .images = []
4040
41- # Make background to enable box zoom
41+ # Make background to enable box zoom.
42+ # Use a size based on limits of the float32 range.
4243 self ._background_geometry = p3 .PlaneGeometry (
43- width = 2 , height = 2 , widthSegments = 1 , heightSegments = 1
44+ width = 6e38 , height = 6e38 , widthSegments = 1 , heightSegments = 1
4445 )
4546 self ._background_material = p3 .MeshBasicMaterial (color = self .background_color )
4647 self ._background_mesh = p3 .Mesh (
@@ -329,18 +330,6 @@ def autoscale(self):
329330 else (1.0 if self .get_yscale () == "linear" else 10.0 )
330331 )
331332
332- self ._background_mesh .geometry = p3 .PlaneGeometry (
333- width = 2 * (self ._xmax - self ._xmin ),
334- height = 2 * (self ._ymax - self ._ymin ),
335- widthSegments = 1 ,
336- heightSegments = 1 ,
337- )
338-
339- self ._background_mesh .position = [
340- 0.5 * (self ._xmin + self ._xmax ),
341- 0.5 * (self ._ymin + self ._ymax ),
342- self ._background_mesh .position [- 1 ],
343- ]
344333 self .reset ()
345334
346335 def add_artist (self , artist ):
@@ -503,8 +492,8 @@ def set_xlim(self, left, right=None):
503492 left = left [0 ]
504493 self ._xmin = left
505494 self ._xmax = right
506- self .camera .left = left
507- self .camera .right = right
495+ self .camera .left = left - self . camera . position [ 0 ]
496+ self .camera .right = right - self . camera . position [ 0 ]
508497 self ._make_xticks ()
509498
510499 def get_ylim (self ):
@@ -519,8 +508,8 @@ def set_ylim(self, bottom, top=None):
519508 bottom = bottom [0 ]
520509 self ._ymin = bottom
521510 self ._ymax = top
522- self .camera .bottom = bottom
523- self .camera .top = top
511+ self .camera .bottom = bottom - self . camera . position [ 1 ]
512+ self .camera .top = top - self . camera . position [ 1 ]
524513 self ._make_yticks ()
525514
526515 def get_xticks (self ):
@@ -577,10 +566,10 @@ def zoom(self, box):
577566 "ymax" : box [3 ],
578567 }
579568 with self .camera .hold_trait_notifications ():
580- self .camera .left = self ._zoom_limits ["xmin" ]
581- self .camera .right = self ._zoom_limits ["xmax" ]
582- self .camera .bottom = self ._zoom_limits ["ymin" ]
583- self .camera .top = self ._zoom_limits ["ymax" ]
569+ self .camera .left = self ._zoom_limits ["xmin" ] - self . camera . position [ 0 ]
570+ self .camera .right = self ._zoom_limits ["xmax" ] - self . camera . position [ 0 ]
571+ self .camera .bottom = self ._zoom_limits ["ymin" ] - self . camera . position [ 1 ]
572+ self .camera .top = self ._zoom_limits ["ymax" ] - self . camera . position [ 1 ]
584573 if self .get_xscale () == "log" :
585574 xlim = (
586575 10.0 ** self ._zoom_limits ["xmin" ],
0 commit comments