diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index d3bc8814545e..a4ce7f4e4ef4 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -536,7 +536,10 @@ def draw_markers( ps_cmd = ['/o {', 'gsave', 'newpath', 'translate'] # don't want the translate to be global lw = gc.get_linewidth() - stroke = lw != 0.0 + alpha = (gc.get_alpha() + if gc.get_forced_alpha() or len(gc.get_rgb()) == 3 + else gc.get_rgb()[3]) + stroke = lw > 0 and alpha > 0 if stroke: ps_cmd.append('%.1f setlinewidth' % lw) jint = gc.get_joinstyle() diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index cc8c617542ae..b948561ea119 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -759,9 +759,8 @@ def draw(self, renderer): gc = renderer.new_gc() self._set_gc_clip(gc) - ln_color_rgba = self._get_rgba_ln_color() - gc.set_foreground(ln_color_rgba, isRGBA=True) - gc.set_alpha(ln_color_rgba[3]) + lc_rgba = mcolors.to_rgba(self._color, self._alpha) + gc.set_foreground(lc_rgba, isRGBA=True) gc.set_antialiased(self._antialiased) gc.set_linewidth(self._linewidth) @@ -785,24 +784,23 @@ def draw(self, renderer): if self._marker and self._markersize > 0: gc = renderer.new_gc() self._set_gc_clip(gc) - rgbaFace = self._get_rgba_face() - rgbaFaceAlt = self._get_rgba_face(alt=True) - edgecolor = self.get_markeredgecolor() - if cbook._str_lower_equal(edgecolor, "none"): - gc.set_linewidth(0) - gc.set_foreground(rgbaFace, isRGBA=True) - else: - gc.set_foreground(edgecolor) - gc.set_linewidth(self._markeredgewidth) - mec = self._markeredgecolor - if (cbook._str_equal(mec, "auto") - and not cbook._str_lower_equal( - self.get_markerfacecolor(), "none")): - gc.set_alpha(rgbaFace[3]) - else: - gc.set_alpha(self.get_alpha()) + gc.set_linewidth(self._markeredgewidth) gc.set_antialiased(self._antialiased) + ec_rgba = mcolors.to_rgba( + self.get_markeredgecolor(), self._alpha) + fc_rgba = mcolors.to_rgba( + self._get_markerfacecolor(), self._alpha) + fcalt_rgba = mcolors.to_rgba( + self._get_markerfacecolor(alt=True), self._alpha) + # If the edgecolor is "auto", it is set according to the *line* + # color but inherits the alpha value of the *face* color, if any. + if (cbook._str_equal(self._markeredgecolor, "auto") + and not cbook._str_lower_equal( + self.get_markerfacecolor(), "none")): + ec_rgba = ec_rgba[:3] + (fc_rgba[3],) + gc.set_foreground(ec_rgba, isRGBA=True) + marker = self._marker tpath, affine = transf_path.get_transformed_points_and_affine() if len(tpath.vertices): @@ -832,22 +830,15 @@ def draw(self, renderer): renderer.draw_markers(gc, marker_path, marker_trans, subsampled, affine.frozen(), - rgbaFace) + fc_rgba) alt_marker_path = marker.get_alt_path() if alt_marker_path: alt_marker_trans = marker.get_alt_transform() alt_marker_trans = alt_marker_trans.scale(w) - if (cbook._str_equal(mec, "auto") - and not cbook._str_lower_equal( - self.get_markerfacecoloralt(), "none")): - gc.set_alpha(rgbaFaceAlt[3]) - else: - gc.set_alpha(self.get_alpha()) - renderer.draw_markers( gc, alt_marker_path, alt_marker_trans, subsampled, - affine.frozen(), rgbaFaceAlt) + affine.frozen(), fcalt_rgba) gc.restore() @@ -892,8 +883,7 @@ def _get_markerfacecolor(self, alt=False): fc = self._markerfacecoloralt else: fc = self._markerfacecolor - - if (isinstance(fc, six.string_types) and fc.lower() == 'auto'): + if cbook._str_lower_equal(fc, 'auto'): if self.get_fillstyle() == 'none': return 'none' else: @@ -1253,9 +1243,6 @@ def update_from(self, other): def _get_rgba_face(self, alt=False): return mcolors.to_rgba(self._get_markerfacecolor(alt=alt), self._alpha) - def _get_rgba_ln_color(self, alt=False): - return mcolors.to_rgba(self._color, self._alpha) - def set_dash_joinstyle(self, s): """ Set the join style for dashed linestyles diff --git a/lib/matplotlib/tests/baseline_images/test_axes/errorbar_mixed.svg b/lib/matplotlib/tests/baseline_images/test_axes/errorbar_mixed.svg index 61da0aca346e..7302d4e74273 100644 --- a/lib/matplotlib/tests/baseline_images/test_axes/errorbar_mixed.svg +++ b/lib/matplotlib/tests/baseline_images/test_axes/errorbar_mixed.svg @@ -1,7 +1,7 @@ - + - - - - - - - - - + + + + + + + + + @@ -132,68 +132,68 @@ L 274.909091 43.2 +" id="m368fc901b1" style="stroke:#000000;stroke-width:0.5;"/> - + +" id="mc63e59a608" style="stroke:#000000;stroke-width:0.5;"/> - + - + - + - + - + - + - + - + - + @@ -204,20 +204,20 @@ L 0 4 +" id="m556f96d829" style="stroke:#000000;stroke-width:0.5;"/> - + +" id="m27e32ca04a" style="stroke:#000000;stroke-width:0.5;"/> - + @@ -238,6 +238,7 @@ Q 39.453125 6.390625 43.28125 13.890625 Q 47.125 21.390625 47.125 36.375 Q 47.125 51.421875 43.28125 58.90625 Q 39.453125 66.40625 31.78125 66.40625 +z M 31.78125 74.21875 Q 44.046875 74.21875 50.515625 64.515625 Q 56.984375 54.828125 56.984375 36.375 @@ -247,6 +248,7 @@ Q 19.53125 -1.421875 13.0625 8.265625 Q 6.59375 17.96875 6.59375 36.375 Q 6.59375 54.828125 13.0625 64.515625 Q 19.53125 74.21875 31.78125 74.21875 +z " id="DejaVuSans-30"/> - + - + @@ -310,12 +312,12 @@ z - + - + @@ -330,12 +332,12 @@ z - + - + @@ -365,12 +367,12 @@ z - + - + @@ -411,6 +413,7 @@ Q 5.515625 40.234375 12.765625 48.109375 Q 20.015625 56 32.328125 56 Q 43.359375 56 49.78125 48.890625 Q 56.203125 41.796875 56.203125 29.59375 +z M 47.21875 32.234375 Q 47.125 39.59375 43.09375 43.984375 Q 39.0625 48.390625 32.421875 48.390625 @@ -484,6 +487,7 @@ Q 5.8125 47.609375 11.28125 51.796875 Q 16.75 56 26.8125 56 Q 31.78125 56 36.171875 55.265625 Q 40.578125 54.546875 44.28125 53.078125 +z " id="DejaVuSans-73"/> @@ -591,28 +597,28 @@ z " style="fill:#ffffff;"/> - - - - - - - - @@ -620,29 +626,29 @@ L 472.224823 195.998601 +" id="m454add2b76" style="stroke:#0000ff;stroke-opacity:0.4;stroke-width:0.5;"/> - - - - - - - - - + + + + + + + + + - - - - - - - - - + + + + + + + + + @@ -657,17 +663,17 @@ C -2.683901 -1.55874 -3 -0.795609 -3 0 C -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 C -1.55874 2.683901 -0.795609 3 0 3 z -" id="mb7d77fda26" style="stroke:#000000;stroke-width:0.5;"/> +" id="m1bffda5d1f" style="stroke:#000000;stroke-opacity:0.4;stroke-width:0.5;"/> - - - - - - - - - + + + + + + + + + @@ -694,60 +700,60 @@ L 518.4 43.2 - + - + - + - + - + - + - + - + - + - + @@ -756,12 +762,12 @@ L 518.4 43.2 - + - + @@ -776,12 +782,12 @@ L 518.4 43.2 - + - + @@ -809,6 +815,7 @@ Q 53.21875 48.921875 51.53125 44.890625 Q 49.859375 40.875 45.40625 35.40625 Q 44.1875 33.984375 37.640625 27.21875 Q 31.109375 20.453125 19.1875 8.296875 +z " id="DejaVuSans-32"/> @@ -821,12 +828,12 @@ Q 31.109375 20.453125 19.1875 8.296875 - + - + @@ -860,12 +867,12 @@ z - + - + @@ -880,6 +887,7 @@ Q 39.65625 6.390625 43.53125 10.953125 Q 47.40625 15.53125 47.40625 23.390625 Q 47.40625 31.296875 43.53125 35.828125 Q 39.65625 40.375 33.015625 40.375 +z M 52.59375 71.296875 L 52.59375 62.3125 Q 48.875 64.0625 45.09375 64.984375 @@ -898,6 +906,7 @@ Q 6.984375 53.65625 15.1875 63.9375 Q 23.390625 74.21875 37.203125 74.21875 Q 40.921875 74.21875 44.703125 73.484375 Q 48.484375 72.75 52.59375 71.296875 +z " id="DejaVuSans-36"/> @@ -910,12 +919,12 @@ Q 48.484375 72.75 52.59375 71.296875 - + - + @@ -930,6 +939,7 @@ Q 38.8125 6.390625 42.859375 10.171875 Q 46.921875 13.96875 46.921875 20.515625 Q 46.921875 27.09375 42.890625 30.859375 Q 38.875 34.625 31.78125 34.625 +z M 21.921875 38.8125 Q 15.578125 40.375 12.03125 44.71875 Q 8.5 49.078125 8.5 55.328125 @@ -947,6 +957,7 @@ Q 19.734375 -1.421875 13.25 4.234375 Q 6.78125 9.90625 6.78125 20.515625 Q 6.78125 27.484375 10.78125 32.3125 Q 14.796875 37.15625 21.921875 38.8125 +z M 18.3125 54.390625 Q 18.3125 48.734375 21.84375 45.5625 Q 25.390625 42.390625 31.78125 42.390625 @@ -956,6 +967,7 @@ Q 45.3125 60.0625 41.71875 63.234375 Q 38.140625 66.40625 31.78125 66.40625 Q 25.390625 66.40625 21.84375 63.234375 Q 18.3125 60.0625 18.3125 54.390625 +z " id="DejaVuSans-38"/> @@ -968,12 +980,12 @@ Q 18.3125 60.0625 18.3125 54.390625 - + - + @@ -1012,6 +1024,7 @@ Q 37.796875 6.203125 41.984375 11.859375 Q 46.1875 17.53125 46.1875 27.296875 Q 46.1875 37.015625 41.984375 42.703125 Q 37.796875 48.390625 30.609375 48.390625 +z M 30.609375 56 Q 42.328125 56 49.015625 48.375 Q 55.71875 40.765625 55.71875 27.296875 @@ -1021,6 +1034,7 @@ Q 18.84375 -1.421875 12.171875 6.21875 Q 5.515625 13.875 5.515625 27.296875 Q 5.515625 40.765625 12.171875 48.375 Q 18.84375 56 30.609375 56 +z " id="DejaVuSans-6f"/> @@ -1160,54 +1178,54 @@ z " style="fill:#ffffff;"/> - - - - - - - - - - - - - - - - @@ -1215,57 +1233,57 @@ L 214.036364 272.060219 +" id="m1981e1242d" style="stroke:#0000ff;stroke-width:0.5;"/> - - - - - - - - - + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - + + + + + + + + + @@ -1309,12 +1327,12 @@ L 274.909091 231.709091 - + - + @@ -1328,12 +1346,12 @@ L 274.909091 231.709091 - + - + @@ -1346,12 +1364,12 @@ L 274.909091 231.709091 - + - + @@ -1364,12 +1382,12 @@ L 274.909091 231.709091 - + - + @@ -1382,12 +1400,12 @@ L 274.909091 231.709091 - + - + @@ -1402,12 +1420,12 @@ L 274.909091 231.709091 - + - + @@ -1423,12 +1441,12 @@ L 274.909091 231.709091 - + - + @@ -1443,12 +1461,12 @@ L 274.909091 231.709091 - + - + @@ -1463,12 +1481,12 @@ L 274.909091 231.709091 - + - + @@ -1483,12 +1501,12 @@ L 274.909091 231.709091 - + - + @@ -1542,54 +1560,54 @@ z " style="fill:#ffffff;"/> - - - - - - - - - - - - - - - - @@ -1597,70 +1615,70 @@ L 457.527273 284.387119 +" id="mef9c074d9e" style="stroke:#008000;stroke-width:2;"/> - - - - - - - - - + + + + + + + + + - - - - - - - - - + + + + + + + + + +" id="maff64b0a79" style="stroke:#008000;stroke-width:2;"/> - - - - - - - - - + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - + + + + + + + + + @@ -1687,12 +1705,12 @@ L 518.4 231.709091 - + - + @@ -1706,12 +1724,12 @@ L 518.4 231.709091 - + - + @@ -1724,12 +1742,12 @@ L 518.4 231.709091 - + - + @@ -1742,12 +1760,12 @@ L 518.4 231.709091 - + - + @@ -1760,12 +1778,12 @@ L 518.4 231.709091 - + - + @@ -1780,12 +1798,12 @@ L 518.4 231.709091 - + - + @@ -1809,12 +1827,12 @@ z - + - + @@ -1830,12 +1848,12 @@ z - + - + @@ -1850,12 +1868,12 @@ z - + - + @@ -1872,296 +1890,296 @@ z +" id="mb12535d6a8" style="stroke:#000000;stroke-width:0.5;"/> - + +" id="m8a2e629618" style="stroke:#000000;stroke-width:0.5;"/> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -2212,6 +2230,7 @@ Q 5.515625 40.1875 11.734375 48.09375 Q 17.96875 56 27.875 56 Q 33.9375 56 38.25 53.625 Q 42.578125 51.265625 45.40625 46.390625 +z M 14.796875 27.296875 Q 14.796875 17.390625 18.875 11.75 Q 22.953125 6.109375 30.078125 6.109375 @@ -2221,6 +2240,7 @@ Q 45.40625 37.203125 41.296875 42.84375 Q 37.203125 48.484375 30.078125 48.484375 Q 22.953125 48.484375 18.875 42.84375 Q 14.796875 37.203125 14.796875 27.296875 +z " id="DejaVuSans-64"/> + - + - + - + diff --git a/lib/matplotlib/tests/baseline_images/test_axes/rgba_markers.svg b/lib/matplotlib/tests/baseline_images/test_axes/rgba_markers.svg index a1ff94a96f94..f0b1b2f3fdc1 100644 --- a/lib/matplotlib/tests/baseline_images/test_axes/rgba_markers.svg +++ b/lib/matplotlib/tests/baseline_images/test_axes/rgba_markers.svg @@ -1,7 +1,7 @@ - + - - + + @@ -50,10 +50,10 @@ z L 50 -50 M -50 -50 L 50 50 -" id="m5255e8aef7" style="stroke:#ff0000;stroke-width:20.000000;"/> +" id="m2bb53bbd7a" style="stroke:#ff0000;stroke-width:20;"/> - - + + @@ -68,10 +68,10 @@ C -44.731685 -25.978994 -50 -13.260155 -50 0 C -50 13.260155 -44.731685 25.978994 -35.355339 35.355339 C -25.978994 44.731685 -13.260155 50 0 50 z -" id="me1f47d7cf6" style="stroke:#ff0000;stroke-width:20.000000;"/> +" id="m774356cf9a" style="stroke:#ff0000;stroke-width:20;"/> - - + + @@ -80,10 +80,10 @@ z L 50 -50 M -50 -50 L 50 50 -" id="m15e5501d3a" style="stroke:#ff0000;stroke-width:20.000000;"/> +" id="m081d77a145" style="stroke:#ff0000;stroke-width:20;"/> - - + + @@ -98,10 +98,10 @@ C -44.731685 -25.978994 -50 -13.260155 -50 0 C -50 13.260155 -44.731685 25.978994 -35.355339 35.355339 C -25.978994 44.731685 -13.260155 50 0 50 z -" id="md637c91b3e" style="stroke:#ff0000;stroke-opacity:0.500000;stroke-width:20.000000;"/> +" id="mf98d41f430" style="stroke:#ff0000;stroke-opacity:0.5;stroke-width:20;"/> - - + + @@ -110,10 +110,10 @@ z L 50 -50 M -50 -50 L 50 50 -" id="m4da6bdd7bd" style="stroke:#ff0000;stroke-opacity:0.500000;stroke-width:20.000000;"/> +" id="m1d398718ef" style="stroke:#ff0000;stroke-opacity:0.5;stroke-width:20;"/> - - + + @@ -128,10 +128,10 @@ C -44.731685 -25.978994 -50 -13.260155 -50 0 C -50 13.260155 -44.731685 25.978994 -35.355339 35.355339 C -25.978994 44.731685 -13.260155 50 0 50 z -" id="mc360218c81" style="stroke:#ff0000;stroke-opacity:0.500000;stroke-width:20.000000;"/> +" id="m1b96511c70" style="stroke:#ff0000;stroke-opacity:0.5;stroke-width:20;"/> - - + + @@ -140,10 +140,10 @@ z L 50 -50 M -50 -50 L 50 50 -" id="m06dcee4ca2" style="stroke:#ff0000;stroke-opacity:0.500000;stroke-width:20.000000;"/> +" id="m4fe50dc6c8" style="stroke:#ff0000;stroke-opacity:0.5;stroke-width:20;"/> - - + + @@ -172,80 +172,80 @@ L 274.909091 43.2 +" id="m368fc901b1" style="stroke:#000000;stroke-width:0.5;"/> - + +" id="mc63e59a608" style="stroke:#000000;stroke-width:0.5;"/> - + - + - + - + - + - + - + - + - + - + - + @@ -256,80 +256,80 @@ L 0 4 +" id="m556f96d829" style="stroke:#000000;stroke-width:0.5;"/> - + +" id="m27e32ca04a" style="stroke:#000000;stroke-width:0.5;"/> - + - + - + - + - + - + - + - + - + - + - + @@ -356,10 +356,10 @@ C -44.731685 -25.978994 -50 -13.260155 -50 0 C -50 13.260155 -44.731685 25.978994 -35.355339 35.355339 C -25.978994 44.731685 -13.260155 50 0 50 z -" id="m258ee76e10" style="stroke:#ff0000;stroke-width:20.000000;"/> +" id="maf4b7325aa" style="stroke:#ff0000;stroke-opacity:0.2;stroke-width:20;"/> - - + + @@ -368,15 +368,15 @@ z L 50 -50 M -50 -50 L 50 50 -" id="m4cae70e294" style="stroke:#ff0000;stroke-width:20.000000;"/> +" id="m7002b850de" style="stroke:#ff0000;stroke-opacity:0.2;stroke-width:20;"/> - - + + - - + + @@ -385,15 +385,15 @@ L 50 50 L 50 -50 M -50 -50 L 50 50 -" id="m105f2a95b9" style="stroke:#ff0000;stroke-width:20.000000;"/> +" id="maf7b03c9e5" style="stroke:#ff0000;stroke-opacity:0.2;stroke-width:20;"/> - - + + - - + + @@ -402,15 +402,15 @@ L 50 50 L 50 -50 M -50 -50 L 50 50 -" id="mfa5c6e318e" style="stroke:#ff0000;stroke-width:20.000000;"/> +" id="m454cbe1679" style="stroke:#ff0000;stroke-opacity:0.2;stroke-width:20;"/> - - + + - - + + @@ -419,10 +419,10 @@ L 50 50 L 50 -50 M -50 -50 L 50 50 -" id="mfed096623b" style="stroke:#ff0000;stroke-width:20.000000;"/> +" id="m7f6b33c891" style="stroke:#ff0000;stroke-opacity:0.2;stroke-width:20;"/> - - + + @@ -449,72 +449,72 @@ L 518.4 43.2 - + - + - + - + - + - + - + - + - + - + - + - + @@ -523,72 +523,72 @@ L 518.4 43.2 - + - + - + - + - + - + - + - + - + - + - + - + @@ -596,11 +596,11 @@ L 518.4 43.2 - - + + - - + + diff --git a/lib/matplotlib/tests/baseline_images/test_axes/test_alpha.svg b/lib/matplotlib/tests/baseline_images/test_axes/test_alpha.svg index 640dd9d7536a..5f7dd673897e 100644 --- a/lib/matplotlib/tests/baseline_images/test_axes/test_alpha.svg +++ b/lib/matplotlib/tests/baseline_images/test_axes/test_alpha.svg @@ -1,7 +1,7 @@ - + - +" id="mcdcf90c5d1" style="stroke:#000000;stroke-linejoin:miter;stroke-opacity:0.5;stroke-width:0.5;"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + @@ -253,7 +253,7 @@ z - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +" style="fill:none;stroke:#ff0000;stroke-linecap:square;stroke-opacity:0.5;stroke-width:10;"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +" style="fill:none;stroke:#ff0000;stroke-linecap:square;stroke-opacity:0.5;stroke-width:10;"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - +" style="fill:none;stroke:#ff0000;stroke-linecap:square;stroke-opacity:0.5;stroke-width:10;"/> + @@ -806,7 +806,7 @@ L -4 0 - + diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index aff0fede59a7..1a5eb4592e5b 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5702,3 +5702,17 @@ def test_empty_errorbar_legend(): def test_plot_columns_cycle_deprecation(): with pytest.warns(MatplotlibDeprecationWarning): plt.plot(np.zeros((2, 2)), np.zeros((2, 3))) + + +def test_markerfacecolor_none_alpha(): + fig1, ax1 = plt.subplots() + ax1.plot(0, "o", mfc="none", alpha=.5) + buf1 = io.BytesIO() + fig1.savefig(buf1) + + fig2, ax2 = plt.subplots() + ax2.plot(0, "o", mfc="w", alpha=.5) + buf2 = io.BytesIO() + fig2.savefig(buf2) + + assert buf1.getvalue() == buf2.getvalue()