Skip to content

Commit 01d3dc2

Browse files
qwhelanTomAugspurger
authored andcommitted
PERF: speed up MPLPlot._apply_axis_properties by skipping expensive tick (#25665)
enumeration where feasible
1 parent a61d823 commit 01d3dc2

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

pandas/plotting/_core.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,20 @@ def _adorn_subplots(self):
474474
self.axes[0].set_title(self.title)
475475

476476
def _apply_axis_properties(self, axis, rot=None, fontsize=None):
477-
labels = axis.get_majorticklabels() + axis.get_minorticklabels()
478-
for label in labels:
479-
if rot is not None:
480-
label.set_rotation(rot)
481-
if fontsize is not None:
482-
label.set_fontsize(fontsize)
477+
""" Tick creation within matplotlib is reasonably expensive and is
478+
internally deferred until accessed as Ticks are created/destroyed
479+
multiple times per draw. It's therefore beneficial for us to avoid
480+
accessing unless we will act on the Tick.
481+
"""
482+
483+
if rot is not None or fontsize is not None:
484+
# rot=0 is a valid setting, hence the explicit None check
485+
labels = axis.get_majorticklabels() + axis.get_minorticklabels()
486+
for label in labels:
487+
if rot is not None:
488+
label.set_rotation(rot)
489+
if fontsize is not None:
490+
label.set_fontsize(fontsize)
483491

484492
@property
485493
def legend_title(self):

0 commit comments

Comments
 (0)