8000 Merge pull request #11105 from anntzer/markerfacecolor-none-alpha · matplotlib/matplotlib@213f399 · GitHub
[go: up one dir, main page]

Skip to content

Commit 213f399

Browse files
authored
Merge pull request #11105 from anntzer/markerfacecolor-none-alpha
FIX: When drawing markers, don't set the GraphicsContext alpha.
2 parents 911a1e9 + 7fbd4c2 commit 213f399

File tree

6 files changed

+667
-641
lines changed

6 files changed

+667
-641
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,10 @@ def draw_markers(
532532
ps_cmd = ['/o {', 'gsave', 'newpath', 'translate'] # don't want the translate to be global
533533

534534
lw = gc.get_linewidth()
535-
stroke = lw != 0.0
535+
alpha = (gc.get_alpha()
536+
if gc.get_forced_alpha() or len(gc.get_rgb()) == 3
537+
else gc.get_rgb()[3])
538+
stroke = lw > 0 and alpha > 0
536539
if stroke:
537540
ps_cmd.append('%.1f setlinewidth' % lw)
538541
jint = gc.get_joinstyle()

lib/matplotlib/lines.py

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -757,9 +757,8 @@ def draw(self, renderer):
757757
gc = renderer.new_gc()
758758
self._set_gc_clip(gc)
759759

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

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

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

831829
renderer.draw_markers(gc, marker_path, marker_trans,
832830
subsampled, affine.frozen(),
833-
rgbaFace)
831+
fc_rgba)
834832

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

850841
gc.restore()
851842

@@ -890,8 +881,7 @@ def _get_markerfacecolor(self, alt=False):
890881
fc = self._markerfacecoloralt
891882
else:
892883
fc = self._markerfacecolor
893-
894-
if (isinstance(fc, six.string_types) and fc.lower() == 'auto'):
884+
if cbook._str_lower_equal(fc, 'auto'):
895885
if self.get_fillstyle() == 'none':
896886
return 'none'
897887
else:
@@ -1251,9 +1241,6 @@ def update_from(self, other):
12511241
def _get_rgba_face(self, alt=False):
12521242
return mcolors.to_rgba(self._get_markerfacecolor(alt=alt), self._alpha)
12531243

1254-
def _get_rgba_ln_color(self, alt=False):
1255-
return mcolors.to_rgba(self._color, self._alpha)
1256-
12571244
def set_dash_joinstyle(self, s):
12581245
"""
12591246
Set the join style for dashed linestyles

0 commit comments

Comments
 (0)
0