Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4f2ecf2

Browse files
committed
Fixes #1860: Unfilled members of collections are not handled correctly in the PDF backend. Also fixes a related bug that alpha could not be set on individual members of a collection.
1 parent 8a17df0 commit 4f2ecf2

File tree

6 files changed

+416
-8
lines changed

6 files changed

+416
-8
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ def _iter_collection(self, gc, master_transform, all_transforms,
352352
gc0 = self.new_gc()
353353
gc0.copy_properties(gc)
354354

355+
original_alpha = gc.get_alpha()
356+
355357
if Nfacecolors == 0:
356358
rgbFace = None
357359

@@ -374,22 +376,28 @@ def _iter_collection(self, gc, master_transform, all_transforms,
374376
yo = -(yp - yo)
375377
if not (np.isfinite(xo) and np.isfinite(yo)):
376378
continue
379+
gc0.set_alpha(original_alpha)
377380
if Nfacecolors:
378381
rgbFace = facecolors[i % Nfacecolors]
379382
if Nedgecolors:
380-
fg = edgecolors[i % Nedgecolors]
381-
if Nfacecolors == 0 and len(fg)==4:
382-
gc0.set_alpha(fg[3])
383-
gc0.set_foreground(fg)
384383
if Nlinewidths:
385384
gc0.set_linewidth(linewidths[i % Nlinewidths])
386385
if Nlinestyles:
387386
gc0.set_dashes(*linestyles[i % Nlinestyles])
388-
if rgbFace is not None and len(rgbFace)==4:
387+
fg = edgecolors[i % Nedgecolors]
388+
if len(fg) == 4:
389+
if fg[3] == 0.0:
390+
gc0.set_linewidth(0)
391+
else:
392+
gc0.set_alpha(gc0.get_alpha() * fg[3])
393+
gc0.set_foreground(fg[:3])
394+
else:
395+
gc0.set_foreground(fg)
396+
if rgbFace is not None and len(rgbFace) == 4:
389397
if rgbFace[3] == 0:
390398
rgbFace = None
391399
else:
392-
gc0.set_alpha(rgbFace[3])
400+
gc0.set_alpha(gc0.get_alpha() * rgbFace[3])
393401
rgbFace = rgbFace[:3]
394402
gc0.set_antialiased(antialiaseds[i % Naa])
395403
if Nurls:

lib/matplotlib/backends/backend_pdf.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,10 +1523,36 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
15231523
offsets, offsetTrans, facecolors, edgecolors,
15241524
linewidths, linestyles, antialiaseds, urls,
15251525
offset_position):
1526+
# We can only reuse the objects if the presence of fill and
1527+
# stroke (and the amount of alpha for each) is the same for
1528+
# all of them
1529+
can_do_optimization = True
1530+
1531+
if not len(facecolors):
1532+
filled = False
1533+
else:
1534+
if np.all(facecolors[:, 3] == facecolors[0, 3]):
1535+
filled = facecolors[0, 3] != 0.0
1536+
else:
1537+
can_do_optimization = False
1538+
1539+
if not len(edgecolors):
1540+
stroked = False
1541+
else:
1542+
if np.all(edgecolors[:, 3] == edgecolors[0, 3]):
1543+
stroked = edgecolors[0, 3] != 0.0
1544+
else:
1545+
can_do_optimization = False
1546+
1547+
if not can_do_optimization:
1548+
return RendererBase.draw_path_collection(
1549+
self, gc, master_transform, paths, all_transforms,
1550+
offsets, offsetTrans, facecolors, edgecolors,
1551+
linewidths, linestyles, antialiaseds, urls,
1552+
offset_position)
1553+
15261554
padding = np.max(linewidths)
15271555
path_codes = []
1528-
filled = len(facecolors)
1529-
stroked = len(edgecolors)
15301556
for i, (path, transform) in enumerate(self._iter_collection_raw_paths(
15311557
master_transform, paths, all_transforms)):
15321558
name = self.file.pathCollectionObject(
Binary file not shown.

0 commit comments

Comments
 (0)