Skip to content

Commit 393c862

Browse files
committed
Merge pull request #11105 from anntzer/markerfacecolor-none-alpha
FIX: When drawing markers, don't set the GraphicsContext alpha. Conflicts: lib/matplotlib/lines.py - keep aliases (which are implemented automatically on master) explicitly in code
1 parent 278ee47 commit 393c862

File tree

6 files changed

+667
-638
lines changed

6 files changed

+667
-638
lines changed

lib/matplotlib/backends/backend_ps.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,10 @@ def draw_markers(
537537
ps_cmd = ['/o {', 'gsave', 'newpath', 'translate'] # don't want the translate to be global
538538

539539
lw = gc.get_linewidth()
540-
stroke = lw != 0.0
540+
alpha = (gc.get_alpha()
541+
if gc.get_forced_alpha() or len(gc.get_rgb()) == 3
542+
else gc.get_rgb()[3])
543+
stroke = lw > 0 and alpha > 0
541544
if stroke:
542545
ps_cmd.append('%.1f setlinewidth' % lw)
543546
jint = gc.get_joinstyle()

lib/matplotlib/lines.py

+20-30
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,8 @@ def draw(self, renderer):
758758
gc = renderer.new_gc()
759759
self._set_gc_clip(gc)
760760

761-
ln_color_rgba = self._get_rgba_ln_color()
762-
gc.set_foreground(ln_color_rgba, isRGBA=True)
763-
gc.set_alpha(ln_color_rgba[3])
761+
lc_rgba = mcolors.to_rgba(self._color, self._alpha)
762+
gc.set_foreground(lc_rgba, isRGBA=True)
764763

765764
gc.set_antialiased(self._antialiased)
766765
gc.set_linewidth(self._linewidth)
@@ -784,24 +783,23 @@ def draw(self, renderer):
784783
if self._marker and self._markersize > 0:
785784
gc = renderer.new_gc()
786785
self._set_gc_clip(gc)
787-
rgbaFace = self._get_rgba_face()
788-
rgbaFaceAlt = self._get_rgba_face(alt=True)
789-
edgecolor = self.get_markeredgecolor()
790-
if cbook._str_lower_equal(edgecolor, "none"):
791-
gc.set_linewidth(0)
792-
gc.set_foreground(rgbaFace, isRGBA=True)
793-
else:
794-
gc.set_foreground(edgecolor)
795-
gc.set_linewidth(self._markeredgewidth)
796-
mec = self._markeredgecolor
797-
if (cbook._str_equal(mec, "auto")
798-
and not cbook._str_lower_equal(
799-
self.get_markerfacecolor(), "none")):
800-
gc.set_alpha(rgbaFace[3])
801-
else:
802-
gc.set_alpha(self.get_alpha())
786+
gc.set_linewidth(self._markeredgewidth)
803787
gc.set_antialiased(self._antialiased)
804788

789+
ec_rgba = mcolors.to_rgba(
790+
self.get_markeredgecolor(), self._alpha)
791+
fc_rgba = mcolors.to_rgba(
792+
self._get_markerfacecolor(), self._alpha)
793+
fcalt_rgba = mcolors.to_rgba(
794+
self._get_markerfacecolor(alt=True), self._alpha)
795+
# If the edgecolor is "auto", it is set according to the *line*
796+
# color but inherits the alpha value of the *face* color, if any.
797+
if (cbook._str_equal(self._markeredgecolor, "auto")
798+
and not cbook._str_lower_equal(
799+
self.get_markerfacecolor(), "none")):
800+
ec_rgba = ec_rgba[:3] + (fc_rgba[3],)
801+
gc.set_foreground(ec_rgba, isRGBA=True)
802+
805803
marker = self._marker
806804
tpath, affine = transf_path.get_transformed_points_and_affine()
807805
if len(tpath.vertices):
@@ -831,22 +829,15 @@ def draw(self, renderer):
831829

832830
renderer.draw_markers(gc, marker_path, marker_trans,
833831
subsampled, affine.frozen(),
834-
rgbaFace)
832+
fc_rgba)
835833

836834
alt_marker_path = marker.get_alt_path()
837835
if alt_marker_path:
838836
alt_marker_trans = marker.get_alt_transform()
839837
alt_marker_trans = alt_marker_trans.scale(w)
840-
if (cbook._str_equal(mec, "auto")
841-
and not cbook._str_lower_equal(
842-
self.get_markerfacecoloralt(), "none")):
843-
gc.set_alpha(rgbaFaceAlt[3])
844-
else:
845-
gc.set_alpha(self.get_alpha())
846-
847838
renderer.draw_markers(
848839
gc, alt_marker_path, alt_marker_trans, subsampled,
849-
affine.frozen(), rgbaFaceAlt)
840+
affine.frozen(), fcalt_rgba)
850841

851842
gc.restore()
852843

@@ -891,8 +882,7 @@ def _get_markerfacecolor(self, alt=False):
891882
fc = self._markerfacecoloralt
892883
else:
893884
fc = self._markerfacecolor
894-
895-
if (isinstance(fc, six.string_types) and fc.lower() == 'auto'):
885+
if cbook._str_lower_equal(fc, 'auto'):
896886
if self.get_fillstyle() == 'none':
897887
return 'none'
898888
else:

0 commit comments

Comments
 (0)