8000 Merge pull request #26344 from oscargus/mopt · randomrahulm/matplotlib@2aee6cc · GitHub
[go: up one dir, main page]

Skip to content

Commit 2aee6cc

Browse files
authored
Merge pull request matplotlib#26344 from oscargus/mopt
Some more micro optimizations
2 parents 50e3717 + c753de2 commit 2aee6cc

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,8 +1375,9 @@ def __clear(self):
13751375
getattr(self, f"share{name}")(share)
13761376
else:
13771377
# Although the scale was set to linear as part of clear,
1378-
# polar requires that it is set again
1379-
axis._set_scale("linear")
1378+
# polar requires that _set_scale is called again
1379+
if self.name == "polar":
1380+
axis._set_scale("linear")
13801381
axis._set_lim(0, 1, auto=True)
13811382
self._update_transScale()
13821383

@@ -2239,8 +2240,7 @@ def add_collection(self, collection, autolim=True):
22392240
Add a `.Collection` to the Axes; return the collection.
22402241
"""
22412242
_api.check_isinstance(mcoll.Collection, collection=collection)
2242-
label = collection.get_label()
2243-
if not label:
2243+
if not collection.get_label():
22442244
collection.set_label(f'_child{len(self._children)}')
22452245
self._children.append(collection)
22462246
collection._remove_method = self._children.remove

lib/matplotlib/collections.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ def get_datalim(self, transData):
256256
# if the offsets are in some coords other than data,
257257
# then don't use them for autoscaling.
258258
return transforms.Bbox.null()
259-
offsets = self.get_offsets()
260259

261260
paths = self.get_paths()
262261
if not len(paths):
@@ -270,6 +269,8 @@ def get_datalim(self, transData):
270269
# transforms.get_affine().contains_branch(transData). But later,
271270
# be careful to only apply the affine part that remains.
272271

272+
offsets = self.get_offsets()
273+
273274
if any(transform.contains_branch_seperately(transData)):
274275
# collections that are just in data units (like quiver)
275276
# can properly have the axes limits set by their shape +

lib/matplotlib/patches.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(self, *,
7272
joinstyle = JoinStyle.miter
7373

7474
self._hatch_color = colors.to_rgba(mpl.rcParams['hatch.color'])
75-
self._fill = True # needed for set_facecolor call
75+
self._fill = bool(fill) # needed for set_facecolor call
7676
if color is not None:
7777
if edgecolor is not None or facecolor is not None:
7878
_api.warn_external(
@@ -87,7 +87,6 @@ def __init__(self, *,
8787
self._unscaled_dash_pattern = (0, None) # offset, dash
8888
self._dash_pattern = (0, None) # offset, dash (scaled by linewidth)
8989

90-
self.set_fill(fill)
9190
self.set_linestyle(linestyle)
9291
self.set_linewidth(linewidth)
9392
self.set_antialiased(antialiased)
@@ -880,8 +879,7 @@ def set_bounds(self, *args):
880879

881880
def get_bbox(self):
882881
"""Return the `.Bbox`."""
883-
x0, y0, x1, y1 = self._convert_units()
884-
return transforms.Bbox.from_extents(x0, y0, x1, y1)
882+
return transforms.Bbox.from_extents(*self._convert_units())
885883

886884
xy = property(get_xy, set_xy)
887885

lib/matplotlib/text.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,10 @@ def update_bbox_position_size(self, renderer):
577577
self._bbox_patch.set_mutation_scale(fontsize_in_pixel)
578578

579579
def _update_clip_properties(self):
580-
clipprops = dict(clip_box=self.clipbox,
581-
clip_path=self._clippath,
582-
clip_on=self._clipon)
583580
if self._bbox_patch:
581+
clipprops = dict(clip_box=self.clipbox,
582+
clip_path=self._clippath,
583+
clip_on=self._clipon)
584584
self._bbox_patch.update(clipprops)
585585

586586
def set_clip_box(self, clipbox):
@@ -1271,10 +1271,9 @@ def set_text(self, s):
12711271
Any object gets converted to its `str` representation, except for
12721272
``None`` which is converted to an empty string.
12731273
"""
1274-
if s is None:
1275-
s = ''
1274+
s = '' if s is None else str(s)
12761275
if s != self._text:
1277-
self._text = str(s)
1276+
self._text = s
12781277
self.stale = True
12791278

12801279
def _preprocess_math(self, s):

0 commit comments

Comments
 (0)
0