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

Commitc935965

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

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

‎lib/matplotlib/axis.py

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

664664

665+
class_LazyTickList(object):
666+
"""
667+
A descriptor for lazy instantiation of tick lists.
668+
669+
See comment above definition of the ``majorTicks`` and ``minorTicks``
670+
attributes.
671+
"""
672+
673+
def__init__(self,major):
674+
self._major=major
675+
676+
def__get__(self,instance,cls):
677+
ifinstanceisNone:
678+
returnself
679+
else:
680+
ifself._major:
681+
instance.majorTicks= [instance._get_tick(major=True)]
682+
returninstance.majorTicks
683+
else:
684+
instance.minorTicks= [instance._get_tick(major=False)]
685+
returninstance.minorTicks
686+
687+
665688
classAxis(artist.Artist):
666689
"""
667690
Public attributes
@@ -696,8 +719,6 @@ def __init__(self, axes, pickradius=15):
696719
self.label=self._get_label()
697720
self.labelpad=rcParams['axes.labelpad']
698721
self.offsetText=self._get_offset_text()
699-
self.majorTicks= []
700-
self.minorTicks= []
701722
self.unit_data=None
702723
self.pickradius=pickradius
703724

@@ -708,6 +729,12 @@ def __init__(self, axes, pickradius=15):
708729
self.cla()
709730
self._set_scale('linear')
710731

732+
# During initialization, Axis objects often create ticks that are later
733+
# unused; this turns out to be a very slow step. Instead, use a custom
734+
# descriptor to make the tick lists lazy and instantiate them as needed.
735+
majorTicks=_LazyTickList(major=True)
736+
minorTicks=_LazyTickList(major=False)
737+
711738
defset_label_coords(self,x,y,transform=None):
712739
"""
713740
Set the coordinates of the label. By default, the x
@@ -798,12 +825,15 @@ def reset_ticks(self):
798825
799826
Each list starts with a single fresh Tick.
800827
"""
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)])
806-
828+
# Restore the lazy tick lists.
829+
try:
830+
delself.majorTicks
831+
exceptAttributeError:
832+
pass
833+
try:
834+
delself.minorTicks
835+
exceptAttributeError:
836+
pass
807837
try:
808838
self.set_clip_path(self.axes.patch)
809839
exceptAttributeError:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp