Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Micro optimization of plotting #26303

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 9 commits into from
Jul 16, 2023
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
11 changes: 9 additions & 2 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def process(self, s, *args, **kwargs):
"""
if self._signals is not None:
_api.check_in_list(self._signals, signal=s)
for cid, ref in list(self.callbacks.get(s, {}).items()):
for ref in list(self.callbacks.get(s, {}).values()):
func = ref()
if func is not None:
try:
Expand Down Expand Up @@ -1634,6 +1634,10 @@ def _safe_first_finite(obj, *, skip_nonfinite=True):
def safe_isfinite(val):
if val is None:
return False
try:
return math.isfinite(val)
except TypeError:
pass
try:
return np.isfinite(val) if np.isscalar(val) else True
except TypeError:
Expand Down Expand Up @@ -1661,7 +1665,10 @@ def safe_isfinite(val):
raise RuntimeError("matplotlib does not "
"support generators as input")
else:
return next((val for val in obj if safe_isfinite(val)), safe_first_element(obj))
for val in obj:
if safe_isfinite(val):
return val
return safe_first_element(obj)


def sanitize_sequence(data):
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,12 @@ def _sanitize_extrema(ex):
ret = float(ex)
return ret

_nth_color_re = re.compile(r"\AC[0-9]+\Z")


def _is_nth_color(c):
"""Return whether *c* can be interpreted as an item in the color cycle."""
return isinstance(c, str) and re.match(r"\AC[0-9]+\Z", c)
return isinstance(c, str) and _nth_color_re.match(c)


def is_color_like(c):
Expand Down
11 changes: 7 additions & 4 deletions lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,14 @@ def set_children(self, *children):
# Parents are stored as weak references, so that if the
# parents are destroyed, references from the children won't
# keep them alive.
id_self = id(self)
for child in children:
# Use weak references so this dictionary won't keep obsolete nodes
# alive; the callback deletes the dictionary entry. This is a
# performance improvement over using WeakValueDictionary.
ref = weakref.ref(
self, lambda _, pop=child._parents.pop, k=id(self): pop(k))
child._parents[id(self)] = ref
self, lambda _, pop=child._parents.pop, k=id_self: pop(k))
child._parents[id_self] = ref

def frozen(self):
"""
Expand Down Expand Up @@ -670,6 +671,8 @@ def intersection(bbox1, bbox2):
y1 = np.minimum(bbox1.ymax, bbox2.ymax)
return Bbox([[x0, y0], [x1, y1]]) if x0 <= x1 and y0 <= y1 else None

_default_minpos = np.array([np.inf, np.inf])


class Bbox(BboxBase):
"""
Expand Down Expand Up @@ -765,7 +768,7 @@ def __init__(self, points, **kwargs):
raise ValueError('Bbox points must be of the form '
'"[[x0, y0], [x1, y1]]".')
self._points = points
self._minpos = np.array([np.inf, np.inf])
self._minpos = _default_minpos.copy()
self._ignore = True
# it is helpful in some contexts to know if the bbox is a
# default or has been mutated; we store the orig points to
Expand Down Expand Up @@ -1773,7 +1776,7 @@ def __array__(self, *args, **kwargs):

def __eq__(self, other):
if getattr(other, "is_affine", False) and hasattr(other, "get_matrix"):
return np.all(self.get_matrix() == other.get_matrix())
return (self.get_matrix() == other.get_matrix()).all()
return NotImplemented

def transform(self, values):
Expand Down