Skip to content

Make NavigationToolbar.configure_subplots return value consistent #30130

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

Merged
merged 1 commit into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3244,7 +3244,7 @@ def _update_view(self):
def configure_subplots(self, *args):
if hasattr(self, "subplot_tool"):
self.subplot_tool.figure.canvas.manager.show()
return
return self.subplot_tool
# This import needs to happen here due to circular imports.
from matplotlib.figure import Figure
with mpl.rc_context({"toolbar": "none"}): # No navbar for the toolfig.
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backend_bases.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ class NavigationToolbar2:
def release_zoom(self, event: Event) -> None: ...
def push_current(self) -> None: ...
subplot_tool: widgets.SubplotTool
def configure_subplots(self, *args): ...
def configure_subplots(self, *args: Any) -> widgets.SubplotTool: ...
def save_figure(self, *args) -> str | None | object: ...
def update(self) -> None: ...
def set_history_buttons(self) -> None: ...
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/tests/test_backend_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ def set_device_pixel_ratio(ratio):
def test_subplottool():
fig, ax = plt.subplots()
with mock.patch("matplotlib.backends.qt_compat._exec", lambda obj: None):
fig.canvas.manager.toolbar.configure_subplots()
tool = fig.canvas.manager.toolbar.configure_subplots()
assert tool is not None
assert tool == fig.canvas.manager.toolbar.configure_subplots()


@pytest.mark.backend('QtAgg', skip_on_importerror=True)
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/tests/test_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ def test_never_update():
plt.show(block=False)

plt.draw() # Test FigureCanvasTkAgg.
fig.canvas.toolbar.configure_subplots() # Test NavigationToolbar2Tk.
tool = fig.canvas.toolbar.configure_subplots() # Test NavigationToolbar2Tk.
assert tool is not None
assert tool == fig.canvas.toolbar.configure_subplots() # Tool is reused internally.
# Test FigureCanvasTk filter_destroy callback
fig.canvas.get_tk_widget().after(100, plt.close, fig)

Expand Down
Loading