Skip to content

When drawing markers, don't set the GraphicsContext alpha. #11105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This effectively treats alpha as a bool for ps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do the same for text.

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()
Expand Down
53 changes: 20 additions & 33 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so _alpha overrides the alpha in self._color if its not None. I'm confused if thats what happened before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. As a general rule, an explicit alpha will override one that comes "with the color" (we can always discuss whether that's a good strategy (I think it's a mess) but that's what we have for now). The exception is the one noted in the comment re: markeredgecolor.
(Before, that happened via get_rgba_ln_color, which I had forgotten to remove but now did.)

gc.set_foreground(lc_rgba, isRGBA=True)

gc.set_antialiased(self._antialiased)
gc.set_linewidth(self._linewidth)
Expand All @@ -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):
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Loading