Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes #1860: Unfilled members of collections are not handled correctl…

…y in the PDF backend. Also fixes a related bug that alpha could not be set on individual members of a collection.
  • Loading branch information...
commit 1ce8484422ab6be1228412f93776b4c15012f555 1 parent 44227e9
Michael Droettboom mdboom authored committed
20 lib/matplotlib/backend_bases.py
View
@@ -362,6 +362,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
@@ -385,22 +387,38 @@ 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:
+<<<<<<< HEAD
fg = edgecolors[i % Nedgecolors]
if Nfacecolors == 0 and len(fg) == 4:
gc0.set_alpha(fg[3])
gc0.set_foreground(fg)
+=======
+>>>>>>> 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.
if Nlinewidths:
gc0.set_linewidth(linewidths[i % Nlinewidths])
if Nlinestyles:
gc0.set_dashes(*linestyles[i % Nlinestyles])
+<<<<<<< HEAD
+=======
+ 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)
+>>>>>>> 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.
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:
30 lib/matplotlib/backends/backend_pdf.py
View
@@ -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(
BIN  lib/matplotlib/tests/baseline_images/test_axes/mixed_collection.pdf
View
Binary file not shown
BIN  lib/matplotlib/tests/baseline_images/test_axes/mixed_collection.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
342 lib/matplotlib/tests/baseline_images/test_axes/mixed_collection.svg
View
@@ -0,0 +1,342 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Created with matplotlib (http://matplotlib.org/) -->
+<svg height="432pt" version="1.1" viewBox="0 0 576 432" width="576pt" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <defs>
+ <style type="text/css">
+*{stroke-linecap:square;stroke-linejoin:round;}
+ </style>
+ </defs>
+ <g id="figure_1">
+ <g id="patch_1">
+ <path d="
+M0 432
+L576 432
+L576 0
+L0 0
+z
+" style="fill:#ffffff;"/>
+ </g>
+ <g id="axes_1">
+ <g id="patch_2">
+ <path d="
+M72 388.8
+L518.4 388.8
+L518.4 43.2
+L72 43.2
+z
+" style="fill:#808080;"/>
+ </g>
+ <g id="PatchCollection_1">
+ <defs>
+ <path d="
+M295.2 -129.6
+C324.797 -129.6 353.185 -138.704 374.113 -154.906
+C395.041 -171.108 406.8 -193.086 406.8 -216
+C406.8 -238.914 395.041 -260.892 374.113 -277.094
+C353.185 -293.296 324.797 -302.4 295.2 -302.4
+C265.603 -302.4 237.215 -293.296 216.287 -277.094
+C195.359 -260.892 183.6 -238.914 183.6 -216
+C183.6 -193.086 195.359 -171.108 216.287 -154.906
+C237.215 -138.704 265.603 -129.6 295.2 -129.6
+z
+" id="C0_0_49e5accb4a"/>
+ </defs>
+ <g clip-path="url(#p7ff5b81e1d)">
+ <use style="fill:none;stroke:#008000;stroke-linecap:butt;" x="0.0" xlink:href="#C0_0_49e5accb4a" y="432.0"/>
+ </g>
+ <g clip-path="url(#p7ff5b81e1d)">
+ <use style="fill:none;stroke:#008000;stroke-linecap:butt;stroke-width:5;" x="24.0" xlink:href="#C0_0_49e5accb4a" y="408.0"/>
+ </g>
+ </g>
+ <g id="PatchCollection_2">
+ <defs>
+ <path d="
+M295.2 -129.6
+C324.797 -129.6 353.185 -138.704 374.113 -154.906
+C395.041 -171.108 406.8 -193.086 406.8 -216
+C406.8 -238.914 395.041 -260.892 374.113 -277.094
+C353.185 -293.296 324.797 -302.4 295.2 -302.4
+C265.603 -302.4 237.215 -293.296 216.287 -277.094
+C195.359 -260.892 183.6 -238.914 183.6 -216
+C183.6 -193.086 195.359 -171.108 216.287 -154.906
+C237.215 -138.704 265.603 -129.6 295.2 -129.6
+z
+" id="C1_0_49e5accb4a"/>
+ </defs>
+ <g clip-path="url(#p7ff5b81e1d)">
+ <use style="fill:none;stroke:#00001a;stroke-linecap:butt;" x="48.0" xlink:href="#C1_0_49e5accb4a" y="432.0"/>
+ </g>
+ <g clip-path="url(#p7ff5b81e1d)">
+ <use style="fill:none;opacity:0.5;stroke:#00001a;stroke-linecap:butt;stroke-width:5;" x="-32.0" xlink:href="#C1_0_49e5accb4a" y="448.0"/>
+ </g>
+ </g>
+ <g id="matplotlib.axis_1">
+ <g id="xtick_1">
+ <g id="line2d_1">
+ <defs>
+ <path d="
+M0 0
+L0 -4" id="mcb557df647" style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;"/>
+ </defs>
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mcb557df647" y="388.8"/>
+ </g>
+ </g>
+ <g id="line2d_2">
+ <defs>
+ <path d="
+M0 0
+L0 4" id="mdad270ee8e" style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;"/>
+ </defs>
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mdad270ee8e" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_2">
+ <g id="line2d_3">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="127.8" xlink:href="#mcb557df647" y="388.8"/>
+ </g>
+ </g>
+ <g id="line2d_4">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="127.8" xlink:href="#mdad270ee8e" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_3">
+ <g id="line2d_5">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="183.6" xlink:href="#mcb557df647" y="388.8"/>
+ </g>
+ </g>
+ <g id="line2d_6">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="183.6" xlink:href="#mdad270ee8e" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_4">
+ <g id="line2d_7">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="239.4" xlink:href="#mcb557df647" y="388.8"/>
+ </g>
+ </g>
+ <g id="line2d_8">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="239.4" xlink:href="#mdad270ee8e" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_5">
+ <g id="line2d_9">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="295.2" xlink:href="#mcb557df647" y="388.8"/>
+ </g>
+ </g>
+ <g id="line2d_10">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="295.2" xlink:href="#mdad270ee8e" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_6">
+ <g id="line2d_11">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="351.0" xlink:href="#mcb557df647" y="388.8"/>
+ </g>
+ </g>
+ <g id="line2d_12">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="351.0" xlink:href="#mdad270ee8e" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_7">
+ <g id="line2d_13">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="406.8" xlink:href="#mcb557df647" y="388.8"/>
+ </g>
+ </g>
+ <g id="line2d_14">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="406.8" xlink:href="#mdad270ee8e" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_8">
+ <g id="line2d_15">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="462.6" xlink:href="#mcb557df647" y="388.8"/>
+ </g>
+ </g>
+ <g id="line2d_16">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="462.6" xlink:href="#mdad270ee8e" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_9">
+ <g id="line2d_17">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#mcb557df647" y="388.8"/>
+ </g>
+ </g>
+ <g id="line2d_18">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#mdad270ee8e" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ </g>
+ <g id="matplotlib.axis_2">
+ <g id="ytick_1">
+ <g id="line2d_19">
+ <defs>
+ <path d="
+M0 0
+L4 0" id="mc8fcea1516" style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;"/>
+ </defs>
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="388.8"/>
+ </g>
+ </g>
+ <g id="line2d_20">
+ <defs>
+ <path d="
+M0 0
+L-4 0" id="m0d5b0a6425" style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;"/>
+ </defs>
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="388.8"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_2">
+ <g id="line2d_21">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="345.6"/>
+ </g>
+ </g>
+ <g id="line2d_22">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="345.6"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_3">
+ <g id="line2d_23">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="302.4"/>
+ </g>
+ </g>
+ <g id="line2d_24">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="302.4"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_4">
+ <g id="line2d_25">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="259.2"/>
+ </g>
+ </g>
+ <g id="line2d_26">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="259.2"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_5">
+ <g id="line2d_27">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="216.0"/>
+ </g>
+ </g>
+ <g id="line2d_28">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="216.0"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_6">
+ <g id="line2d_29">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="172.8"/>
+ </g>
+ </g>
+ <g id="line2d_30">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="172.8"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_7">
+ <g id="line2d_31">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="129.6"/>
+ </g>
+ </g>
+ <g id="line2d_32">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="129.6"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_8">
+ <g id="line2d_33">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="86.4"/>
+ </g>
+ </g>
+ <g id="line2d_34">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="86.4"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_9">
+ <g id="line2d_35">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="43.2"/>
+ </g>
+ </g>
+ <g id="line2d_36">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ </g>
+ <g id="patch_3">
+ <path d="
+M72 43.2
+L518.4 43.2" style="fill:none;stroke:#000000;"/>
+ </g>
+ <g id="patch_4">
+ <path d="
+M518.4 388.8
+L518.4 43.2" style="fill:none;stroke:#000000;"/>
+ </g>
+ <g id="patch_5">
+ <path d="
+M72 388.8
+L518.4 388.8" style="fill:none;stroke:#000000;"/>
+ </g>
+ <g id="patch_6">
+ <path d="
+M72 388.8
+L72 43.2" style="fill:none;stroke:#000000;"/>
+ </g>
+ </g>
+ </g>
+ <defs>
+ <clipPath id="p7ff5b81e1d">
+ <rect height="345.6" width="446.4" x="72.0" y="43.2"/>
+ </clipPath>
+ </defs>
+</svg>
33 lib/matplotlib/tests/test_axes.py
View
@@ -1242,6 +1242,7 @@ def test_eb_line_zorder():
ax.set_title("errorbar zorder test")
+<<<<<<< HEAD
@image_comparison(baseline_images=['step_linestyle'], remove_text=True)
def test_step_linestyle():
x = y = np.arange(10)
@@ -1263,3 +1264,35 @@ def test_step_linestyle():
if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
+=======
+@image_comparison(baseline_images=['mixed_collection'], remove_text=True)
+def test_mixed_collection():
+ from matplotlib import patches
+ from matplotlib import collections
+
+ x = range(10)
+
+ # First illustrate basic pyplot interface, using defaults where possible.
+ fig = plt.figure()
+ ax = fig.add_subplot(1,1,1)
+
+ c = patches.Circle((8, 8), radius=4, facecolor='none', edgecolor='green')
+
+ # PDF can optimize this one
+ p1 = collections.PatchCollection([c], match_original=True)
+ p1.set_offsets([[0, 0], [24, 24]])
+ p1.set_linewidths([1, 5])
+
+ # PDF can't optimize this one, because the alpha of the edge changes
+ p2 = collections.PatchCollection([c], match_original=True)
+ p2.set_offsets([[48, 0], [-32, -16]])
+ p2.set_linewidths([1, 5])
+ p2.set_edgecolors([[0, 0, 0.1, 1.0], [0, 0, 0.1, 0.5]])
+
+ ax.patch.set_color('0.5')
+ ax.add_collection(p1)
+ ax.add_collection(p2)
+
+ ax.set_xlim(0, 16)
+ ax.set_ylim(0, 16)
+>>>>>>> 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.
Please sign in to comment.
Something went wrong with that request. Please try again.