Skip to content

Commit

Permalink
Fixes matplotlib#1860: Unfilled members of collections are not handle…
Browse files Browse the repository at this point in the history
…d correctly in the PDF backend. Also fixes a related bug that alpha could not be set on individual members of a collection.
  • Loading branch information
mdboom committed Mar 27, 2013
1 parent 8a17df0 commit 4f2ecf2
Show file tree
Hide file tree
Showing 6 changed files with 416 additions and 8 deletions.
20 changes: 14 additions & 6 deletions lib/matplotlib/backend_bases.py
Expand Up @@ -352,6 +352,8 @@ def _iter_collection(self, gc, master_transform, all_transforms,
gc0 = self.new_gc()
gc0.copy_properties(gc)

original_alpha = gc.get_alpha()

if Nfacecolors == 0:
rgbFace = None

Expand All @@ -374,22 +376,28 @@ def _iter_collection(self, gc, master_transform, all_transforms,
yo = -(yp - yo)
if not (np.isfinite(xo) and np.isfinite(yo)):
continue
gc0.set_alpha(original_alpha)
if Nfacecolors:
rgbFace = facecolors[i % Nfacecolors]
if Nedgecolors:
fg = edgecolors[i % Nedgecolors]
if Nfacecolors == 0 and len(fg)==4:
gc0.set_alpha(fg[3])
gc0.set_foreground(fg)
if Nlinewidths:
gc0.set_linewidth(linewidths[i % Nlinewidths])
if Nlinestyles:
gc0.set_dashes(*linestyles[i % Nlinestyles])
if rgbFace is not None and len(rgbFace)==4:
fg = edgecolors[i % Nedgecolors]
if len(fg) == 4:
if fg[3] == 0.0:
gc0.set_linewidth(0)
else:
gc0.set_alpha(gc0.get_alpha() * fg[3])
gc0.set_foreground(fg[:3])
else:
gc0.set_foreground(fg)
if rgbFace is not None and len(rgbFace) == 4:
if rgbFace[3] == 0:
rgbFace = None
else:
gc0.set_alpha(rgbFace[3])
gc0.set_alpha(gc0.get_alpha() * rgbFace[3])
rgbFace = rgbFace[:3]
gc0.set_antialiased(antialiaseds[i % Naa])
if Nurls:
Expand Down
30 changes: 28 additions & 2 deletions lib/matplotlib/backends/backend_pdf.py
Expand Up @@ -1523,10 +1523,36 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
offsets, offsetTrans, facecolors, edgecolors,
linewidths, linestyles, antialiaseds, urls,
offset_position):
# We can only reuse the objects if the presence of fill and
# stroke (and the amount of alpha for each) is the same for
# all of them
can_do_optimization = True

if not len(facecolors):
filled = False
else:
if np.all(facecolors[:, 3] == facecolors[0, 3]):
filled = facecolors[0, 3] != 0.0
else:
can_do_optimization = False

if not len(edgecolors):
stroked = False
else:
if np.all(edgecolors[:, 3] == edgecolors[0, 3]):
stroked = edgecolors[0, 3] != 0.0
else:
can_do_optimization = False

if not can_do_optimization:
return RendererBase.draw_path_collection(
self, gc, master_transform, paths, all_transforms,
offsets, offsetTrans, facecolors, edgecolors,
linewidths, linestyles, antialiaseds, urls,
offset_position)

padding = np.max(linewidths)
path_codes = []
filled = len(facecolors)
stroked = len(edgecolors)
for i, (path, transform) in enumerate(self._iter_collection_raw_paths(
master_transform, paths, all_transforms)):
name = self.file.pathCollectionObject(
Expand Down
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4f2ecf2

Please sign in to comment.