@@ -271,25 +271,41 @@ def draw(self, renderer):
271
271
from matplotlib .patheffects import PathEffectRenderer
272
272
renderer = PathEffectRenderer (self .get_path_effects (), renderer )
273
273
274
+ # If the collection is made up of a single shape/color/stroke,
275
+ # it can be rendered once and blitted multiple times, using
276
+ # `draw_markers` rather than `draw_path_collection`. This is
277
+ # *much* faster for Agg, and results in smaller file sizes in
278
+ # PDF/SVG/PS.
279
+
274
280
trans = self .get_transforms ()
275
281
facecolors = self .get_facecolor ()
276
282
edgecolors = self .get_edgecolor ()
283
+ do_single_path_optimization = False
277
284
if (len (paths ) == 1 and len (trans ) <= 1 and
278
285
len (facecolors ) == 1 and len (edgecolors ) == 1 and
279
286
len (self ._linewidths ) == 1 and
280
287
self ._linestyles == [(None , None )] and
281
288
len (self ._antialiaseds ) == 1 and len (self ._urls ) == 1 and
282
289
self .get_hatch () is None ):
290
+ if len (trans ):
291
+ combined_transform = (transforms .Affine2D (trans [0 ]) +
292
+ transform )
293
+ else :
294
+ combined_transform = transform
295
+ extents = paths [0 ].get_extents (combined_transform )
296
+ width , height = renderer .get_canvas_width_height ()
297
+ if (extents .width < width and
298
+ extents .height < height ):
299
+ do_single_path_optimization = True
300
+
301
+ if do_single_path_optimization :
283
302
gc .set_foreground (tuple (edgecolors [0 ]))
284
303
gc .set_linewidth (self ._linewidths [0 ])
285
304
gc .set_linestyle (self ._linestyles [0 ])
286
305
gc .set_antialiased (self ._antialiaseds [0 ])
287
306
gc .set_url (self ._urls [0 ])
288
- if len (trans ):
289
- transform = (transforms .Affine2D (trans [0 ]) +
290
- transform )
291
307
renderer .draw_markers (
292
- gc , paths [0 ], transform .frozen (),
308
+ gc , paths [0 ], combined_transform .frozen (),
293
309
mpath .Path (offsets ), transOffset , tuple (facecolors [0 ]))
294
310
else :
295
311
renderer .draw_path_collection (
0 commit comments