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

Skip to content

Improve performance of plt.clf() #26243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,11 @@ def __clear(self):
for axis in self._axis_map.values():
axis.clear() # Also resets the scale to linear.
for spine in self.spines.values():
# avoid expensive methods in the clearing of the spine, gh-26243
tmp_axis = spine.axis
spine.axis = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a context manager that will do this setting/resetting in matplotlib.cbook._setattr_cm.

spine.clear()
spine.axis = tmp_axis

self.ignore_existing_data_limits = True
self.callbacks = cbook.CallbackRegistry(
Expand Down