Skip to content

Speedup Line2D marker color setting. #20197

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
May 11, 2021
Merged
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
58 changes: 29 additions & 29 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,19 @@ def set_marker(self, marker):
self._marker = MarkerStyle(marker, self._marker.get_fillstyle())
self.stale = True

def _set_markercolor(self, attr, val):
if val is None:
val = 'auto'
current = getattr(self, attr)
if current is None:
self.stale = True
else:
neq = current != val
# Much faster than `np.any(current != val)` if no arrays are used.
if neq.any() if isinstance(neq, np.ndarray) else neq:
self.stale = True
setattr(self, attr, val)

def set_markeredgecolor(self, ec):
"""
Set the marker edge color.
Expand All @@ -1155,55 +1168,42 @@ def set_markeredgecolor(self, ec):
----------
ec : color
"""
if ec is None:
ec = 'auto'
if (self._markeredgecolor is None
or np.any(self._markeredgecolor != ec)):
self.stale = True
self._markeredgecolor = ec
self._set_markercolor("_markeredgecolor", ec)

def set_markeredgewidth(self, ew):
def set_markerfacecolor(self, fc):
"""
Set the marker edge width in points.
Set the marker face color.

Parameters
----------
ew : float
Marker edge width, in points.
fc : color
"""
if ew is None:
ew = rcParams['lines.markeredgewidth']
if self._markeredgewidth != ew:
self.stale = True
self._markeredgewidth = ew
self._set_markercolor("_markerfacecolor", fc)

def set_markerfacecolor(self, fc):
def set_markerfacecoloralt(self, fc):
"""
Set the marker face color.
Set the alternate marker face color.

Parameters
----------
fc : color
"""
if fc is None:
fc = 'auto'
if np.any(self._markerfacecolor != fc):
self.stale = True
self._markerfacecolor = fc
self._set_markercolor("_markerfacecoloralt", fc)

def set_markerfacecoloralt(self, fc):
def set_markeredgewidth(self, ew):
"""
Set the alternate marker face color.
Set the marker edge width in points.

Parameters
----------
fc : color
ew : float
Marker edge width, in points.
"""
if fc is None:
fc = 'auto'
if np.any(self._markerfacecoloralt != fc):
if ew is None:
ew = rcParams['lines.markeredgewidth']
if self._markeredgewidth != ew:
self.stale = True
self._markerfacecoloralt = fc
self._markeredgewidth = ew

def set_markersize(self, sz):
"""
Expand Down