Add blitting support to button widgets#23457
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)? |
| if self.drawon: | ||
| self.ax.figure.canvas.draw() | ||
| if self._useblit: | ||
| self.ax.draw_artist(self.ax) |
There was a problem hiding this comment.
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.
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
pytestpasses).flake8-docstringsand 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).