@@ -2043,16 +2043,11 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
20432043 name = self .file .pathCollectionObject (
20442044 gc , path , transform , padding , filled , stroked )
20452045 path_codes .append (name )
2046- # Compute the extent of each marker path to enable per-marker
2047- # bounds checking. This allows us to skip markers that are
2048- # completely outside the visible canvas while preserving markers
2049- # that are partially visible.
2050- if len (path .vertices ):
2051- bbox = path .get_extents (transform )
2052- # Store half-width and half-height for efficient bounds checking
2053- path_extents .append ((bbox .width / 2 , bbox .height / 2 ))
2054- else :
2055- path_extents .append ((0 , 0 ))
2046+ # Compute each transformed path's exact bounds for per-marker
2047+ # canvas checks. Offsets are not necessarily full canvas-space
2048+ # centers, e.g. for collections using AffineDeltaTransform, so
2049+ # cull based on the final path bounds translated by the offset.
2050+ path_extents .append (path .get_extents (transform ).frozen ())
20562051
20572052 # Create a mapping from path_id to extent for efficient lookup
20582053 path_extent_map = dict (zip (path_codes , path_extents ))
@@ -2068,26 +2063,12 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
20682063 facecolors , edgecolors , linewidths , linestyles ,
20692064 antialiaseds , urls , offset_position , hatchcolors = hatchcolors ):
20702065
2071- # Optimization: Fast path for markers with centers inside canvas.
2072- # This avoids the dictionary lookup for the common case where
2073- # markers are visible, improving performance for large scatter plots.
2074- if 0 <= xo <= canvas_width and 0 <= yo <= canvas_height :
2075- # Marker center is inside canvas - definitely render it
2076- self .check_gc (gc0 , rgbFace )
2077- dx , dy = xo - lastx , yo - lasty
2078- output (1 , 0 , 0 , 1 , dx , dy , Op .concat_matrix , path_id ,
2079- Op .use_xobject )
2080- lastx , lasty = xo , yo
2081- continue
2082-
2083- # Marker center is outside canvas - check if partially visible.
2084- # Skip markers completely outside visible canvas bounds to reduce
2085- # PDF file size. Use per-marker extents to handle large markers
2086- # correctly: only skip if the marker's bounding box doesn't
2087- # intersect the canvas at all.
2088- extent_x , extent_y = path_extent_map [path_id ]
2089- if not (- extent_x <= xo <= canvas_width + extent_x
2090- and - extent_y <= yo <= canvas_height + extent_y ):
2066+ # Skip markers completely outside the canvas to reduce PDF size.
2067+ # Use the translated path bounds, not the offset alone: the offset
2068+ # need not be the marker center in canvas coordinates.
2069+ bbox = path_extent_map [path_id ]
2070+ if (bbox .x1 + xo < 0 or bbox .x0 + xo > canvas_width
2071+ or bbox .y1 + yo < 0 or bbox .y0 + yo > canvas_height ):
20912072 continue
20922073
20932074 self .check_gc (gc0 , rgbFace )
0 commit comments