-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add blitting support to button widgets #23457
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
Conversation
As a test, you can run: import matplotlib.pyplot as plt
from matplotlib._api import suppress_matplotlib_deprecation_warning
from matplotlib.widgets import Button, CheckButtons, RadioButtons
for useblit in [False, True]:
fig, axs = plt.subplots(10, 10, constrained_layout=True)
fig.suptitle(f'Button(useblit={useblit})')
fig._buttons = [
Button(ax, f'Test {i}', useblit=useblit)
for i, ax in enumerate(axs.flat)
]
for button_class in (CheckButtons, RadioButtons):
for useblit in [False, True]:
fig, axs = plt.subplots(10, 10, constrained_layout=True)
fig.suptitle(f'{button_class.__name__}(useblit={useblit})')
fig._buttons = [
button_class(ax, [f'Test {4*i+j}' for j in range(4)],
useblit=useblit)
for i, ax in enumerate(axs.flat)
]
for button in fig._buttons[::2]:
with suppress_matplotlib_deprecation_warning():
if isinstance(button, RadioButtons):
button.circles # Trigger deprecated behaviour.
else:
button.lines
plt.show() which for |
Rebased to work with |
Looks good, but perhaps this should wait for #24474 to be merged first (and blitting adapted to the new checkboxes as well)? |
@@ -209,7 +214,11 @@ def _motion(self, event): | |||
if not colors.same_color(c, self.ax.get_facecolor()): | |||
self.ax.set_facecolor(c) | |||
if self.drawon: | |||
self.ax.figure.canvas.draw() | |||
if self._useblit: | |||
self.ax.draw_artist(self.ax) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you confirm that Button doesn't use copy_from_bbox/restore_region like the other two widgets because the button covers the entire axes anyways?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and it's strictly a rectangle, so copy_from_bbox
/restore_region
would effectively be directly overwritten immediately.
I also wonder if the default should be |
Seems reasonable. |
PR Summary
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).