From e435aaecb1fdbaf3c18dfabb1cc8d693af1cae0e Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 2 Feb 2021 16:23:14 +0000 Subject: [PATCH] Add warning when subplot kwargs are ignored --- lib/matplotlib/pyplot.py | 4 ++++ lib/matplotlib/tests/test_pyplot.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 8f8f9544677e..94253aefa3cc 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -1232,6 +1232,10 @@ def subplot(*args, **kwargs): # If no existing axes match, then create a new one. if ax is None: ax = fig.add_subplot(*args, **kwargs) + elif kwargs: + _api.warn_external(f"An Axes with subplot spec {args} already exists. " + "The existing Axes will be returned, with all " + "keyword arguments ignored.") bbox = ax.bbox axes_to_delete = [] diff --git a/lib/matplotlib/tests/test_pyplot.py b/lib/matplotlib/tests/test_pyplot.py index 6b520aea30d4..1cfcb0d0035f 100644 --- a/lib/matplotlib/tests/test_pyplot.py +++ b/lib/matplotlib/tests/test_pyplot.py @@ -153,3 +153,11 @@ def test_nested_ion_ioff(): with plt.ioff(): plt.ion() assert not mpl.is_interactive() + + +def test_subplot_warning(): + ax1 = plt.subplot(2, 1, 1) + with pytest.warns(UserWarning, match='An Axes with subplot spec ' + r'\(2, 1, 1\) already exists'): + ax2 = plt.subplot(2, 1, 1, polar=True) + assert ax1 is ax2 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy