Skip to content

Commit 5fa8c5b

Browse files
authored
Merge pull request #9911 from anntzer/get_rgba_face
2 parents 7249249 + ee13342 commit 5fa8c5b

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

lib/matplotlib/backends/backend_ps.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -513,13 +513,13 @@ def draw_path(self, gc, path, transform, rgbFace=None):
513513
"""
514514
Draws a Path instance using the given affine transform.
515515
"""
516-
clip = (rgbFace is None and gc.get_hatch_path() is None)
516+
clip = rgbFace is None and gc.get_hatch_path() is None
517517
simplify = path.should_simplify and clip
518-
ps = self._convert_path(
519-
path, transform, clip=clip, simplify=simplify)
518+
ps = self._convert_path(path, transform, clip=clip, simplify=simplify)
520519
self._draw_ps(ps, gc, rgbFace)
521520

522-
def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None):
521+
def draw_markers(
522+
self, gc, marker_path, marker_trans, path, trans, rgbFace=None):
523523
"""
524524
Draw the markers defined by path at each of the positions in x
525525
and y. path coordinates are points, x and y coords will be
@@ -528,7 +528,9 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
528528
if debugPS: self._pswriter.write('% draw_markers \n')
529529

530530
if rgbFace:
531-
if rgbFace[0]==rgbFace[1] and rgbFace[0]==rgbFace[2]:
531+
if len(rgbFace) == 4 and rgbFace[3] == 0:
532+
return
533+
if rgbFace[0] == rgbFace[1] == rgbFace[2]:
532534
ps_color = '%1.3f setgray' % rgbFace[0]
533535
else:
534536
ps_color = '%1.3f %1.3f %1.3f setrgbcolor' % rgbFace[:3]

lib/matplotlib/cbook/__init__.py

+20
Original file line numberDiff line numberDiff line change
@@ -2767,3 +2767,23 @@ def _topmost_artist(
27672767
in reverse order.
27682768
"""
27692769
return _cached_max(reversed(artists))
2770+
2771+
2772+
def _str_equal(obj, s):
2773+
"""Return whether *obj* is a string equal to string *s*.
2774+
2775+
This helper solely exists to handle the case where *obj* is a numpy array,
2776+
because in such cases, a naive ``obj == s`` would yield an array, which
2777+
cannot be used in a boolean context.
2778+
"""
2779+
return isinstance(obj, six.string_types) and obj == s
2780+
2781+
2782+
def _str_lower_equal(obj, s):
2783+
"""Return whether *obj* is a string equal, when lowercased, to string *s*.
2784+
2785+
This helper solely exists to handle the case where *obj* is a numpy array,
2786+
because in such cases, a naive ``obj == s`` would yield an array, which
2787+
cannot be used in a boolean context.
2788+
"""
2789+
return isinstance(obj, six.string_types) and obj.lower() == s

lib/matplotlib/lines.py

+10-16
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,
@@ -792,16 +792,16 @@ def draw(self, renderer):
792792
rgbaFace = self._get_rgba_face()
793793
rgbaFaceAlt = self._get_rgba_face(alt=True)
794794
edgecolor = self.get_markeredgecolor()
795-
if (isinstance(edgecolor, six.string_types)
796-
and edgecolor.lower() == 'none'):
795+
if cbook._str_lower_equal(edgecolor, "none"):
797796
gc.set_linewidth(0)
798797
gc.set_foreground(rgbaFace, isRGBA=True)
799798
else:
800799
gc.set_foreground(edgecolor)
801800
gc.set_linewidth(self._markeredgewidth)
802801
mec = self._markeredgecolor
803-
if (isinstance(mec, six.string_types) and mec == 'auto' and
804-
rgbaFace is not None):
802+
if (cbook._str_equal(mec, "auto")
803+
and not cbook._str_lower_equal(
804+
self.get_markerfacecolor(), "none")):
805805
gc.set_alpha(rgbaFace[3])
806806
else:
807807
gc.set_alpha(self.get_alpha())
@@ -827,8 +827,7 @@ def draw(self, renderer):
827827
marker_trans = marker.get_transform()
828828
w = renderer.points_to_pixels(self._markersize)
829829

830-
if (isinstance(marker.get_marker(), six.string_types) and
831-
marker.get_marker() == ','):
830+
if cbook._str_equal(marker.get_marker(), ","):
832831
gc.set_linewidth(0)
833832
else:
834833
# Don't scale for pixels, and don't stroke them
@@ -842,8 +841,9 @@ def draw(self, renderer):
842841
if alt_marker_path:
843842
alt_marker_trans = marker.get_alt_transform()
844843
alt_marker_trans = alt_marker_trans.scale(w)
845-
if (isinstance(mec, six.string_types) and mec == 'auto' and
846-
rgbaFaceAlt is not None):
844+
if (cbook._str_equal(mec, "auto")
845+
and not cbook._str_lower_equal(
846+
self.get_markerfacecoloralt(), "none")):
847847
gc.set_alpha(rgbaFaceAlt[3])
848848
else:
849849
gc.set_alpha(self.get_alpha())
@@ -1260,13 +1260,7 @@ def update_from(self, other):
12601260
self._drawstyle = other._drawstyle
12611261

12621262
def _get_rgba_face(self, alt=False):
1263-
facecolor = self._get_markerfacecolor(alt=alt)
1264-
if (isinstance(facecolor, six.string_types)
1265-
and facecolor.lower() == 'none'):
1266-
rgbaFace = None
1267-
else:
1268-
rgbaFace = mcolors.to_rgba(facecolor, self._alpha)
1269-
return rgbaFace
1263+
return mcolors.to_rgba(self._get_markerfacecolor(alt=alt), self._alpha)
12701264

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

0 commit comments

Comments
 (0)