1- from matplotlib .backend_bases import RendererBase
1+ from typing import Tuple , Union
2+ from matplotlib .axes import Axes
3+ from matplotlib .backend_bases import RendererBase , GraphicsContextBase
4+ from matplotlib .font_manager import FontProperties
25from matplotlib .patches import Rectangle
6+ from matplotlib .texmanager import TexManager
37from matplotlib .transforms import Bbox , IdentityTransform , Affine2D , \
4- TransformedPatchPath
8+ TransformedPatchPath , Transform
59from matplotlib .path import Path
610import matplotlib ._image as _image
711import numpy as np
812from matplotlib .image import _interpd_
913from matplotview ._docs import dynamic_doc_string , get_interpolation_list_str
1014
15+ ColorTup = Union [None , Tuple [float , float , float , float ], Tuple [float , float , float ]]
1116
1217class _TransformRenderer (RendererBase ):
1318 """
@@ -19,12 +24,12 @@ class _TransformRenderer(RendererBase):
1924 @dynamic_doc_string (interp_list = get_interpolation_list_str ())
2025 def __init__ (
2126 self ,
22- base_renderer ,
23- mock_transform ,
24- transform ,
25- bounding_axes ,
26- image_interpolation = "nearest" ,
27- scale_linewidths = True
27+ base_renderer : RendererBase ,
28+ mock_transform : Transform ,
29+ transform : Transform ,
30+ bounding_axes : Axes ,
31+ image_interpolation : str = "nearest" ,
32+ scale_linewidths : bool = True
2833 ):
2934 """
3035 Constructs a new TransformRender.
@@ -80,10 +85,10 @@ def __init__(
8085 )
8186
8287 @property
83- def bounding_axes (self ):
88+ def bounding_axes (self ) -> Axes :
8489 return self .__bounding_axes
8590
86- def _scale_gc (self , gc ) :
91+ def _scale_gc (self , gc : GraphicsContextBase ) -> GraphicsContextBase :
8792 with np .errstate (all = 'ignore' ):
8893 transfer_transform = self ._get_transfer_transform (
8994 IdentityTransform ()
@@ -103,14 +108,14 @@ def _scale_gc(self, gc):
103108
104109 return new_gc
105110
106- def _get_axes_display_box (self ):
111+ def _get_axes_display_box (self ) -> Bbox :
107112 """
108113 Private method, get the bounding box of the child axes in display
109114 coordinates.
110115 """
111116 return self .__bounding_axes .get_window_extent ()
112117
113- def _get_transfer_transform (self , orig_transform ) :
118+ def _get_transfer_transform (self , orig_transform : Transform ) -> Transform :
114119 """
115120 Private method, returns the transform which translates and scales
116121 coordinates as if they were originally plotted on the child axes
@@ -141,43 +146,63 @@ def _get_transfer_transform(self, orig_transform):
141146 # We copy all of the properties of the renderer we are mocking, so that
142147 # artists plot themselves as if they were placed on the original renderer.
143148 @property
144- def height (self ):
149+ def height (self ) -> int :
145150 return self .__renderer .get_canvas_width_height ()[1 ]
146151
147152 @property
148- def width (self ):
153+ def width (self ) -> int :
149154 return self .__renderer .get_canvas_width_height ()[0 ]
150155
151- def get_text_width_height_descent (self , s , prop , ismath ):
156+ def get_text_width_height_descent (
157+ self ,
158+ s : str ,
159+ prop : FontProperties ,
160+ ismath : bool
161+ ) -> Tuple [float , float , float ]:
152162 return self .__renderer .get_text_width_height_descent (s , prop , ismath )
153163
154- def get_canvas_width_height (self ):
164+ def get_canvas_width_height (self ) -> Tuple [ float , float ] :
155165 return self .__renderer .get_canvas_width_height ()
156166
157- def get_texmanager (self ):
167+ def get_texmanager (self ) -> TexManager :
158168 return self .__renderer .get_texmanager ()
159169
160- def get_image_magnification (self ):
170+ def get_image_magnification (self ) -> float :
161171 return self .__renderer .get_image_magnification ()
162172
163- def _get_text_path_transform (self , x , y , s , prop , angle , ismath ):
164- return self .__renderer ._get_text_path_transform (x , y , s , prop , angle ,
165- ismath )
173+ def _get_text_path_transform (
174+ self ,
175+ x : float ,
176+ y : float ,
177+ s : str ,
178+ prop : FontProperties ,
179+ angle : float ,
180+ ismath : bool
181+ ) -> Transform :
182+ return self .__renderer ._get_text_path_transform (
183+ x , y , s , prop , angle , ismath
184+ )
166185
167- def option_scale_image (self ):
186+ def option_scale_image (self ) -> bool :
168187 return False
169188
170- def points_to_pixels (self , points ) :
189+ def points_to_pixels (self , points : float ) -> float :
171190 return self .__renderer .points_to_pixels (points )
172191
173- def flipy (self ):
192+ def flipy (self ) -> bool :
174193 return self .__renderer .flipy ()
175194
176- def new_gc (self ):
195+ def new_gc (self ) -> GraphicsContextBase :
177196 return self .__renderer .new_gc ()
178197
179198 # Actual drawing methods below:
180- def draw_path (self , gc , path , transform , rgbFace = None ):
199+ def draw_path (
200+ self ,
201+ gc : GraphicsContextBase ,
202+ path : Path ,
203+ transform : Transform ,
204+ rgbFace : ColorTup = None
205+ ):
181206 # Convert the path to display coordinates, but if it was originally
182207 # drawn on the child axes.
183208 path = path .deepcopy ()
@@ -203,7 +228,16 @@ def draw_path(self, gc, path, transform, rgbFace=None):
203228
204229 self .__renderer .draw_path (gc , path , IdentityTransform (), rgbFace )
205230
206- def _draw_text_as_path (self , gc , x , y , s , prop , angle , ismath ):
231+ def _draw_text_as_path (
232+ self ,
233+ gc : GraphicsContextBase ,
234+ x : float ,
235+ y : float ,
236+ s : str ,
237+ prop : FontProperties ,
238+ angle : float ,
239+ ismath : bool
240+ ):
207241 # If the text field is empty, don't even try rendering it...
208242 if ((s is None ) or (s .strip () == "" )):
209243 return
@@ -212,7 +246,13 @@ def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath):
212246 # checked above... (Above case causes error)
213247 super ()._draw_text_as_path (gc , x , y , s , prop , angle , ismath )
214248
215- def draw_gouraud_triangle (self , gc , points , colors , transform ):
249+ def draw_gouraud_triangle (
250+ self ,
251+ gc : GraphicsContextBase ,
252+ points : np .ndarray ,
253+ colors : np .ndarray ,
254+ transform : Transform
255+ ):
216256 # Pretty much identical to draw_path, transform the points and adjust
217257 # clip to the child axes bounding box.
218258 points = self ._get_transfer_transform (transform ).transform (points )
@@ -233,7 +273,14 @@ def draw_gouraud_triangle(self, gc, points, colors, transform):
233273 IdentityTransform ())
234274
235275 # Images prove to be especially messy to deal with...
236- def draw_image (self , gc , x , y , im , transform = None ):
276+ def draw_image (
277+ self ,
278+ gc : GraphicsContextBase ,
279+ x : float ,
280+ y : float ,
281+ im : np .ndarray ,
282+ transform : Transform = None
283+ ):
237284 mag = self .get_image_magnification ()
238285 shift_data_transform = self ._get_transfer_transform (
239286 IdentityTransform ()
0 commit comments