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

Skip to content

Commit 2990fd3

Browse files
committed
Optimize setting units to None when they're already None.
Previously, we skipped the axis update when replacing a non-None unit by the same unit, but (needlessly) not when replacing None by itself. Also the newer implementation is simpler.
1 parent c221853 commit 2990fd3

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

lib/matplotlib/axis.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,18 +1508,12 @@ def set_units(self, u):
15081508
----------
15091509
u : units tag
15101510
"""
1511-
pchanged = False
1512-
if u is None:
1513-
self.units = None
1514-
pchanged = True
1515-
else:
1516-
if u != self.units:
1517-
self.units = u
1518-
pchanged = True
1519-
if pchanged:
1520-
self._update_axisinfo()
1521-
self.callbacks.process('units')
1522-
self.callbacks.process('units finalize')
1511+
if u == self.units:
1512+
return
1513+
self.units = u
1514+
self._update_axisinfo()
1515+
self.callbacks.process('units')
1516+
self.callbacks.process('units finalize')
15231517
self.stale = True
15241518

15251519
def get_units(self):

0 commit comments

Comments
 (0)