Skip to content

Commit 5962817

Browse files
committed
PERF: speed up MPLPlot._apply_axis_properties by skipping expensive tick
enumeration where feasible
1 parent 1017382 commit 5962817

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
@@ -468,12 +468,20 @@ def _adorn_subplots(self):
468468
self.axes[0].set_title(self.title)
469469

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

478486
@property
479487
def legend_title(self):

0 commit comments

Comments
 (0)