From 56fcef5b01745482b19182dd1a8e5832035a1ab1 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Sat, 23 Oct 2021 20:26:03 +0200 Subject: [PATCH] FIX: re-instate ability to have position in axes --- lib/matplotlib/pyplot.py | 6 +++++- lib/matplotlib/tests/test_pyplot.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 06719adf3a6f..d0c259502d21 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -1059,8 +1059,12 @@ def axes(arg=None, **kwargs): plt.axes((left, bottom, width, height), facecolor='w') """ fig = gcf() + pos = kwargs.pop('position', None) if arg is None: - return fig.add_subplot(**kwargs) + if pos is None: + return fig.add_subplot(**kwargs) + else: + return fig.add_axes(pos, **kwargs) else: return fig.add_axes(arg, **kwargs) diff --git a/lib/matplotlib/tests/test_pyplot.py b/lib/matplotlib/tests/test_pyplot.py index d0d38c78ed7f..0105c6f22d47 100644 --- a/lib/matplotlib/tests/test_pyplot.py +++ b/lib/matplotlib/tests/test_pyplot.py @@ -1,4 +1,5 @@ import difflib +import numpy as np import subprocess import sys from pathlib import Path @@ -320,3 +321,17 @@ def test_polar_second_call(): ln2, = plt.polar(1.57, .5, 'bo') assert isinstance(ln2, mpl.lines.Line2D) assert ln1.axes is ln2.axes + + +def test_fallback_position(): + # check that position kwarg works if rect not supplied + axref = plt.axes([0.2, 0.2, 0.5, 0.5]) + axtest = plt.axes(position=[0.2, 0.2, 0.5, 0.5]) + np.testing.assert_allclose(axtest.bbox.get_points(), + axref.bbox.get_points()) + + # check that position kwarg ignored if rect is supplied + axref = plt.axes([0.2, 0.2, 0.5, 0.5]) + axtest = plt.axes([0.2, 0.2, 0.5, 0.5], position=[0.1, 0.1, 0.8, 0.8]) + np.testing.assert_allclose(axtest.bbox.get_points(), + axref.bbox.get_points()) 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