1010from matplotlib .figure import Figure
1111from matplotlib .path import Path
1212from matplotlib .mathtext import MathTextParser
13+ from matplotlib .colors import colorConverter
1314
1415
1516
@@ -48,34 +49,47 @@ def set_width_height (self, width, height):
4849 self .width , self .height = width , height
4950
5051 def draw_path (self , gc , path , transform , rgbFace = None ):
51- path = transform .transform_path (path )
52- for points , code in path .iter_segments ():
53- if code == Path .MOVETO :
54- gc .moveto (points )
55- elif code == Path .LINETO :
56- gc .lineto (points )
57- elif code == Path .CURVE3 :
58- gc .curve3 (points )
59- elif code == Path .CURVE4 :
60- gc .curve4 (points )
61- elif code == Path .CLOSEPOLY :
62- gc .closepoly ()
6352 if rgbFace is not None :
6453 rgbFace = tuple (rgbFace )
65- gc .stroke (rgbFace )
54+ if gc != self .gc :
55+ n = self .gc .level () - gc .level ()
56+ for i in range (n ): self .gc .restore ()
57+ self .gc = gc
58+ gc .draw_path (path , transform , rgbFace )
59+
60+ def draw_markers (self , gc , marker_path , marker_trans , path , trans , rgbFace = None ):
61+ if rgbFace is not None :
62+ rgbFace = tuple (rgbFace )
63+ if gc != self .gc :
64+ n = self .gc .level () - gc .level ()
65+ for i in range (n ): self .gc .restore ()
66+ self .gc = gc
67+ gc .draw_markers (marker_path , marker_trans , path , trans , rgbFace )
68+
69+ def draw_path_collection (self , * args ):
70+ gc = self .gc
71+ args = args [:13 ]
72+ gc .draw_path_collection (* args )
73+
74+ def draw_quad_mesh (self , * args ):
75+ gc = self .gc
76+ gc .draw_quad_mesh (* args )
6677
6778 def new_gc (self ):
6879 self .gc .reset ()
6980 return self .gc
7081
7182 def draw_image (self , x , y , im , bbox , clippath = None , clippath_trans = None ):
72- self .gc .set_clip_rectangle (bbox )
7383 im .flipud_out ()
7484 nrows , ncols , data = im .as_rgba_str ()
75- self .gc .draw_image (x , y , nrows , ncols , data )
85+ self .gc .draw_image (x , y , nrows , ncols , data , bbox , clippath , clippath_trans )
7686 im .flipud_out ()
7787
7888 def draw_tex (self , gc , x , y , s , prop , angle ):
89+ if gc != self .gc :
90+ n = self .gc .level () - gc .level ()
91+ for i in range (n ): self .gc .restore ()
92+ self .gc = gc
7993 # todo, handle props, angle, origins
8094 size = prop .get_size_in_points ()
8195 texmanager = self .get_texmanager ()
@@ -88,12 +102,20 @@ def draw_tex(self, gc, x, y, s, prop, angle):
88102 gc .draw_mathtext (x , y , angle , Z )
89103
90104 def _draw_mathtext (self , gc , x , y , s , prop , angle ):
105+ if gc != self .gc :
106+ n = self .gc .level () - gc .level ()
107+ for i in range (n ): self .gc .restore ()
108+ self .gc = gc
91109 size = prop .get_size_in_points ()
92110 ox , oy , width , height , descent , image , used_characters = \
93111 self .mathtext_parser .parse (s , self .dpi , prop )
94112 gc .draw_mathtext (x , y , angle , 255 - image .as_array ())
95113
96114 def draw_text (self , gc , x , y , s , prop , angle , ismath = False ):
115+ if gc != self .gc :
116+ n = self .gc .level () - gc .level ()
117+ for i in range (n ): self .gc .restore ()
118+ self .gc = gc
97119 if ismath :
98120 self ._draw_mathtext (gc , x , y , s , prop , angle )
99121 else :
@@ -143,6 +165,11 @@ def __init__(self):
143165 GraphicsContextBase .__init__ (self )
144166 _macosx .GraphicsContext .__init__ (self )
145167
168+ def set_foreground (self , fg , isRGB = False ):
169+ if not isRGB :
170+ fg = colorConverter .to_rgb (fg )
171+ _macosx .GraphicsContext .set_foreground (self , fg )
172+
146173 def set_clip_rectangle (self , box ):
147174 GraphicsContextBase .set_clip_rectangle (self , box )
148175 if not box : return
@@ -152,19 +179,7 @@ def set_clip_path(self, path):
152179 GraphicsContextBase .set_clip_path (self , path )
153180 if not path : return
154181 path = path .get_fully_transformed_path ()
155- for points , code in path .iter_segments ():
156- if code == Path .MOVETO :
157- self .moveto (points )
158- elif code == Path .LINETO :
159- self .lineto (points )
160- elif code == Path .CURVE3 :
161- self .curve3 (points )
162- elif code == Path .CURVE4 :
163- self .curve4 (points )
164- elif code == Path .CLOSEPOLY :
165- self .closepoly ()
166- self .clip_path ()
167-
182+ _macosx .GraphicsContext .set_clip_path (self , path )
168183
169184########################################################################
170185#
0 commit comments