8000 Make _get_rgba_face actually always return a RGBA. · matplotlib/matplotlib@56c8925 · GitHub
[go: up one dir, main page]

Skip to content

Commit 56c8925

Browse files
committed
Make _get_rgba_face actually always return a RGBA.
_get_rgba_face is an internal function that is only use to set the graphicscontext's foreground color (in Line2D.draw); it is always effectively called as `gc.set_foreground(line._get_rgba_face(...), isRGBA=True)`. So it makes sense to have it actually always return a RGBA quadruplet, including when the color is "none" (in which case `mcolors.to_rgba` returns (0, 0, 0, 0) regardless of alpha, which works just fine). This removes the need for third party graphicscontexts to handle non-RGBA-quadruplets (specifically, None) even when set_foreground is actually called with isRGBA=True.
1 parent 0ddae6e commit 56c8925

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,3 +2766,11 @@ def _topmost_artist(
27662766
in reverse order.
27672767
"""
27682768
return _cached_max(reversed(artists))
2769+
2770+
2771+
def _str_equal(obj, s):
2772+
"""Return whether an object is a string equal to another string.
2773+
2774+
This helper solely exists to handle the case where *obj* is a numpy array.
2775+
"""
2776+
return isinstance(obj, six.string_types) and obj == s

lib/matplotlib/lines.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import numpy as np
1515

16-
from . import artist, colors as mcolors, docstring, rcParams
16+
from . import artist, cbook, colors as mcolors, docstring, rcParams
1717
from .artist import Artist, allow_rasterization
1818
from .cbook import (
1919
_to_unmasked_float_array, iterable, is_numlike, ls_mapper, ls_mapper_r,
@@ -793,16 +793,16 @@ def draw(self, renderer):
793793
rgbaFace = self._get_rgba_face()
794794
rgbaFaceAlt = self._get_rgba_face(alt=True)
795795
edgecolor = self.get_markeredgecolor()
796-
if (isinstance(edgecolor, six.string_types)
797-
and edgecolor.lower() == 'none'):
796+
if cbook._str_equal(edgecolor, "none"):
798797
gc.set_linewidth(0)
799798
gc.set_foreground(rgbaFace, isRGBA=True)
800799
else:
801800
gc.set_foreground(edgecolor)
802801
gc.set_linewidth(self._markeredgewidth)
803802
mec = self._markeredgecolor
804-
if (isinstance(mec, six.string_types) and mec == 'auto' and
805-
rgbaFace is not None):
803+
if (cbook._str_equal(mec, "auto")
804+
and not cbook._str_equal(self.get_markerfacecolor(),
805+
"none")):
806806
gc.set_alpha(rgbaFace[3])
807807
else:
808808
gc.set_alpha(self.get_alpha())
@@ -1257,13 +1257,7 @@ def update_from(self, other):
12571257
self._drawstyle = other._drawstyle
12581258

12591259
def _get_rgba_face(self, alt=False):
1260-
facecolor = self._get_markerfacecolor(alt=alt)
1261-
if (isinstance(facecolor, six.string_types)
1262-
and facecolor.lower() == 'none'):
1263-
rgbaFace = None
1264-
else:
1265-
rgbaFace = mcolors.to_rgba(facecolor, self._alpha)
1266-
return rgbaFace
1260+
return mcolors.to_rgba(self._get_markerfacecolor(alt=alt), self._alpha)
12671261

12681262
def _get_rgba_ln_color(self, alt=False):
12691263
return mcolors.to_rgba(self._color, self._alpha)

0 commit comments

Comments
 (0)
0