From 24ac7333af87e0351fe9e72f654bdea6e6579218 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Sun, 31 Jan 2021 22:46:45 -0800 Subject: [PATCH 1/3] FIX: allow add option for Axes3D(fig) --- lib/matplotlib/axes/_base.py | 2 ++ lib/matplotlib/figure.py | 6 ++++++ lib/mpl_toolkits/mplot3d/axes3d.py | 10 ++++++++++ lib/mpl_toolkits/tests/test_mplot3d.py | 6 +++--- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index b85275bce970..73f211a6998a 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -645,6 +645,8 @@ def __init__(self, fig, rect, if yscale: self.set_yscale(yscale) + # remove when Axis3d deprecation expires and this kwarg is removed: + kwargs.pop('add', None) self.update(kwargs) for name, axis in self._get_axis_map().items(): diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index f4e5183e3838..2da7a460e735 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -579,6 +579,8 @@ def add_axes(self, *args, **kwargs): projection_class, kwargs = self._process_projection_requirements( *args, **kwargs) + # remove this when deprecation for Axes3d(add=True) ends: + kwargs['add'] = False # create the new axes using the axes class given a = projection_class(self, rect, **kwargs) return self._add_axes_internal(a) @@ -708,6 +710,10 @@ def add_subplot(self, *args, **kwargs): args = tuple(map(int, str(args[0]))) projection_class, kwargs = self._process_projection_requirements( *args, **kwargs) + + # remove this when deprecation for Axes3d(add=True) ends: + kwargs['add'] = False + ax = subplot_class_factory(projection_class)(self, *args, **kwargs) return self._add_axes_internal(ax) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 14d2b9f4a89d..75af7f07e4ca 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -97,6 +97,8 @@ def __init__( self._shared_z_axes.join(self, sharez) self._adjustable = 'datalim' + add = kwargs.pop("add", True) + super().__init__( fig, rect, frameon=True, box_aspect=box_aspect, *args, **kwargs ) @@ -125,6 +127,14 @@ def __init__( pseudo_bbox = self.transLimits.inverted().transform([(0, 0), (1, 1)]) self._pseudo_w, self._pseudo_h = pseudo_bbox[1] - pseudo_bbox[0] + if add: + _api.warn_deprecated( + "3.4", message="Axes3D(fig) adding itself " + "to the figure is deprecated since %(since)s and will " + "no longer work %(removal)s; this is consistent with " + "other axes classes. Use fig.add_subplot(projection='3d')") + self.figure.add_axes(self) + # mplot3d currently manages its own spines and needs these turned off # for bounding box calculations self.spines[:].set_visible(False) diff --git a/lib/mpl_toolkits/tests/test_mplot3d.py b/lib/mpl_toolkits/tests/test_mplot3d.py index c7d1818b9c40..e524fcd769d8 100644 --- a/lib/mpl_toolkits/tests/test_mplot3d.py +++ b/lib/mpl_toolkits/tests/test_mplot3d.py @@ -3,7 +3,7 @@ import pytest -from mpl_toolkits.mplot3d import Axes3D, axes3d, proj3d, art3d +from mpl_toolkits.mplot3d import axes3d, proj3d, art3d import matplotlib as mpl from matplotlib.backend_bases import MouseButton from matplotlib import cm @@ -725,7 +725,7 @@ def test_add_collection3d_zs_scalar(): @mpl3d_image_comparison(['axes3d_labelpad.png'], remove_text=False) def test_axes3d_labelpad(): fig = plt.figure() - ax = fig.add_axes(Axes3D(fig)) + ax = fig.add_subplot(projection='3d') # labelpad respects rcParams assert ax.xaxis.labelpad == mpl.rcParams['axes.labelpad'] # labelpad can be set in set_label @@ -1132,7 +1132,7 @@ def test_inverted_cla(): def test_ax3d_tickcolour(): fig = plt.figure() - ax = Axes3D(fig) + ax = fig.add_subplot(projection="3d") ax.tick_params(axis='x', colors='red') ax.tick_params(axis='y', colors='red') From dcc91750ed9a3504e000c85129b99ef5f6ed7f11 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Mon, 1 Feb 2021 07:19:19 -0800 Subject: [PATCH 2/3] Fix --- lib/matplotlib/tests/test_collections.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index 9fe73e3b892a..bdb72d045f0b 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -382,7 +382,6 @@ def test_EllipseCollection(): @image_comparison(['polycollection_close.png'], remove_text=True) def test_polycollection_close(): - from mpl_toolkits.mplot3d import Axes3D vertsQuad = [ [[0., 0.], [0., 1.], [1., 1.], [1., 0.]], @@ -391,7 +390,7 @@ def test_polycollection_close(): [[3., 0.], [3., 1.], [4., 1.], [4., 0.]]] fig = plt.figure() - ax = fig.add_axes(Axes3D(fig)) + ax = fig.add_subplot(projection='3d') colors = ['r', 'g', 'b', 'y', 'k'] zpos = list(range(5)) From 31b6fe7376a239d773ca7992c364a4a91e5c1810 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Mon, 1 Feb 2021 07:28:10 -0800 Subject: [PATCH 3/3] FIX: get tests working --- lib/matplotlib/tests/test_collections.py | 3 ++- lib/mpl_toolkits/tests/test_mplot3d.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index bdb72d045f0b..3523645ee999 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -382,6 +382,7 @@ def test_EllipseCollection(): @image_comparison(['polycollection_close.png'], remove_text=True) def test_polycollection_close(): + from mpl_toolkits.mplot3d import Axes3D vertsQuad = [ [[0., 0.], [0., 1.], [1., 1.], [1., 0.]], @@ -390,7 +391,7 @@ def test_polycollection_close(): [[3., 0.], [3., 1.], [4., 1.], [4., 0.]]] fig = plt.figure() - ax = fig.add_subplot(projection='3d') + ax = fig.add_axes(Axes3D(fig, add=False)) colors = ['r', 'g', 'b', 'y', 'k'] zpos = list(range(5)) diff --git a/lib/mpl_toolkits/tests/test_mplot3d.py b/lib/mpl_toolkits/tests/test_mplot3d.py index e524fcd769d8..66c61be873e3 100644 --- a/lib/mpl_toolkits/tests/test_mplot3d.py +++ b/lib/mpl_toolkits/tests/test_mplot3d.py @@ -3,7 +3,7 @@ import pytest -from mpl_toolkits.mplot3d import axes3d, proj3d, art3d +from mpl_toolkits.mplot3d import Axes3D, axes3d, proj3d, art3d import matplotlib as mpl from matplotlib.backend_bases import MouseButton from matplotlib import cm @@ -725,7 +725,8 @@ def test_add_collection3d_zs_scalar(): @mpl3d_image_comparison(['axes3d_labelpad.png'], remove_text=False) def test_axes3d_labelpad(): fig = plt.figure() - ax = fig.add_subplot(projection='3d') + ax = Axes3D(fig, add=False) + fig.add_axes(ax) # labelpad respects rcParams assert ax.xaxis.labelpad == mpl.rcParams['axes.labelpad'] # labelpad can be set in set_label 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