@@ -286,6 +286,20 @@ def describe(self):
286286 }
287287
288288
289+ @dataclass
290+ class FigureImageContainer (ImageContainer ):
291+ def describe (self ):
292+ imshape = list (self .image .shape )
293+ imshape [:2 ] = ("M" , "N" )
294+
295+ return {
296+ "x" : Desc ((), "data" ),
297+ "y" : Desc ((), "data" ),
298+ "image" : Desc (tuple (imshape ), "data" ),
299+ }
300+
301+
302+
289303class _ImageBase (mcolorizer .ColorizingArtist ):
290304 """
291305 Base class for images.
@@ -358,6 +372,7 @@ def get_container(self):
358372
359373 def _get_graph (self ):
360374 # TODO see about getting rid of self.axes
375+ # TODO move to cbook or similar
361376 ax = self .axes
362377 if ax is None :
363378 return Graph ([])
@@ -1516,40 +1531,48 @@ def __init__(self, fig,
15161531 origin = origin
15171532 )
15181533 self .set_figure (fig )
1519- self .ox = offsetx
1520- self .oy = offsety
1534+ self ._container = FigureImageContainer (
1535+ np .array (offsetx ),
1536+ np .array (offsety ),
1537+ np .array ([[]]),
1538+ )
15211539 self ._internal_update (kwargs )
15221540 self .magnification = 1.0
15231541
15241542 def get_extent (self ):
15251543 """Return the image extent as tuple (left, right, bottom, top)."""
1526- numrows , numcols = self .get_size ()
1527- return (- 0.5 + self .ox , numcols - 0.5 + self .ox ,
1528- - 0.5 + self .oy , numrows - 0.5 + self .oy )
1544+ q , _ = self ._container .query (self ._get_graph ())
1545+ ox = q ["x" ]
1546+ oy = q ["y" ]
1547+ A = q ["image" ]
1548+
1549+ numrows , numcols , * _ = A .shape
1550+ return (- 0.5 + ox , numcols - 0.5 + ox ,
1551+ - 0.5 + oy , numrows - 0.5 + oy )
15291552
15301553 def make_image (self , renderer , magnification = 1.0 , unsampled = False ):
15311554 # docstring inherited
1555+ q , _ = self ._container .query (self ._get_graph ())
1556+ ox = q ["x" ]
1557+ oy = q ["y" ]
1558+ A = q ["image" ]
1559+
15321560 fig = self .get_figure (root = True )
15331561 fac = renderer .dpi / fig .dpi
15341562 # fac here is to account for pdf, eps, svg backends where
15351563 # figure.dpi is set to 72. This means we need to scale the
15361564 # image (using magnification) and offset it appropriately.
1537- bbox = Bbox ([[self . ox / fac , self . oy / fac ],
1538- [(self . ox / fac + self . _A .shape [1 ]),
1539- (self . oy / fac + self . _A .shape [0 ])]])
1565+ bbox = Bbox ([[ox / fac , oy / fac ],
1566+ [(ox / fac + A .shape [1 ]),
1567+ (oy / fac + A .shape [0 ])]])
15401568 width , height = fig .get_size_inches ()
15411569 width *= renderer .dpi
15421570 height *= renderer .dpi
15431571 clip = Bbox ([[0 , 0 ], [width , height ]])
15441572 return self ._make_image (
1545- self . _A , bbox , bbox , clip , magnification = magnification / fac ,
1573+ A , bbox , bbox , clip , magnification = magnification / fac ,
15461574 unsampled = unsampled , round_to_pixel_border = False )
15471575
1548- def set_data (self , A ):
1549- """Set the image array."""
1550- super ().set_data (A )
1551- self .stale = True
1552-
15531576
15541577class BboxImage (_ImageBase ):
15551578 """
@@ -1625,6 +1648,12 @@ def __init__(self, bbox,
16251648 )
16261649 self .bbox = bbox
16271650
1651+ self ._container = ImageContainer (
1652+ np .asarray ([]), # Unused for BboxImage, kept for container hierarchy
1653+ np .asarray ([]), # Unused for BboxImage, kept for container hierarchy
1654+ np .asarray ([[]]),
1655+ )
1656+
16281657 def get_window_extent (self , renderer = None ):
16291658 if isinstance (self .bbox , BboxBase ):
16301659 return self .bbox
@@ -1645,14 +1674,17 @@ def contains(self, mouseevent):
16451674
16461675 def make_image (self , renderer , magnification = 1.0 , unsampled = False ):
16471676 # docstring inherited
1677+ q , _ = self ._container .query (self ._get_graph ())
1678+ A = q ["image" ]
1679+
16481680 width , height = renderer .get_canvas_width_height ()
16491681 bbox_in = self .get_window_extent (renderer ).frozen ()
16501682 bbox_in ._points /= [width , height ]
16511683 bbox_out = self .get_window_extent (renderer )
16521684 clip = Bbox ([[0 , 0 ], [width , height ]])
16531685 self ._transform = BboxTransformTo (clip )
16541686 return self ._make_image (
1655- self . _A ,
1687+ A ,
16561688 bbox_in , bbox_out , clip , magnification , unsampled = unsampled )
16571689
16581690
0 commit comments