Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite2c7538

Browse files
committed
Alternate implementation of lazy ticks.
Speeds up creation of 10x10 subplots ~4-fold (from 2.7s to 0.7s).
1 parent6044a57 commite2c7538

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

‎lib/matplotlib/axis.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,22 @@ class Ticker(object):
662662
formatter=None
663663

664664

665+
class_LazyTickList(object):
666+
def__init__(self,major):
667+
self._major=major
668+
669+
def__get__(self,instance,cls):
670+
ifinstanceisNone:
671+
returnself
672+
else:
673+
ifself._major:
674+
instance.majorTicks= [instance._get_tick(major=True)]
675+
returninstance.majorTicks
676+
else:
677+
instance.minorTicks= [instance._get_tick(major=False)]
678+
returninstance.minorTicks
679+
680+
665681
classAxis(artist.Artist):
666682
"""
667683
Public attributes
@@ -696,8 +712,6 @@ def __init__(self, axes, pickradius=15):
696712
self.label=self._get_label()
697713
self.labelpad=rcParams['axes.labelpad']
698714
self.offsetText=self._get_offset_text()
699-
self.majorTicks= []
700-
self.minorTicks= []
701715
self.unit_data=None
702716
self.pickradius=pickradius
703717

@@ -708,6 +722,12 @@ def __init__(self, axes, pickradius=15):
708722
self.cla()
709723
self._set_scale('linear')
710724

725+
# During initialization, Axis objects often create ticks that are later
726+
# unused; this turns out to be a very slow step. Instead, use a custom
727+
# descriptor to make the tick lists lazy and instantiate them as needed.
728+
majorTicks=_LazyTickList(major=True)
729+
minorTicks=_LazyTickList(major=False)
730+
711731
defset_label_coords(self,x,y,transform=None):
712732
"""
713733
Set the coordinates of the label. By default, the x
@@ -798,11 +818,15 @@ def reset_ticks(self):
798818
799819
Each list starts with a single fresh Tick.
800820
"""
801-
delself.majorTicks[:]
802-
delself.minorTicks[:]
803-
804-
self.majorTicks.extend([self._get_tick(major=True)])
805-
self.minorTicks.extend([self._get_tick(major=False)])
821+
# Restore the lazy tick lists.
822+
try:
823+
delself.majorTicks
824+
exceptAttributeError:
825+
pass
826+
try:
827+
delself.minorTicks
828+
exceptAttributeError:
829+
pass
806830
self._lastNumMajorTicks=1
807831
self._lastNumMinorTicks=1
808832

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp