From 6dbcaf1e8114ca5337ea2b8727975234225464b8 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 15 May 2017 04:27:26 -0400 Subject: [PATCH 1/3] Don't clear Spines and Axis twice in Axes.__init__. Both these classes have called their own .cla() method in their .__init__() method, so don't call it again in Axes.cla() if doing Axes.__init__(). --- lib/matplotlib/axes/_base.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 7948c14de8e9..9ac220fc1256 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -479,6 +479,7 @@ def __init__(self, fig, rect, """ % {'scale': ' | '.join( [repr(x) for x in mscale.get_scale_names()])} martist.Artist.__init__(self) + self._in_init = True if isinstance(rect, mtransforms.Bbox): self._position = rect else: @@ -576,6 +577,8 @@ def __init__(self, fig, rect, right=rcParams['ytick.right'] and rcParams['ytick.major.right'], which='major') + self._in_init = False + def __getstate__(self): # The renderer should be re-created by the figure, and then cached at # that point. @@ -965,10 +968,13 @@ def cla(self): xaxis_visible = self.xaxis.get_visible() yaxis_visible = self.yaxis.get_visible() - self.xaxis.cla() - self.yaxis.cla() - for name, spine in six.iteritems(self.spines): - spine.cla() + # Don't clear during __init__ because they're already been cleared by + # their own __init__. + if not self._in_init: + self.xaxis.cla() + self.yaxis.cla() + for name, spine in six.iteritems(self.spines): + spine.cla() self.ignore_existing_data_limits = True self.callbacks = cbook.CallbackRegistry() From 72821afa9a8126eaa6908768a9c0cc05564870e2 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 15 May 2017 20:11:05 -0400 Subject: [PATCH 2/3] Don't clear a new Axis when registering with a Spine. If the Axis was just created, calling Axis.cla is redundant because it just happened. --- lib/matplotlib/axes/_base.py | 8 ++++---- lib/matplotlib/spines.py | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 9ac220fc1256..6f0839eaf851 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -610,11 +610,11 @@ def get_window_extent(self, *args, **kwargs): def _init_axis(self): "move this out of __init__ because non-separable axes don't use it" self.xaxis = maxis.XAxis(self) - self.spines['bottom'].register_axis(self.xaxis) - self.spines['top'].register_axis(self.xaxis) + self.spines['bottom'].register_axis(self.xaxis, _init=True) + self.spines['top'].register_axis(self.xaxis, _init=True) self.yaxis = maxis.YAxis(self) - self.spines['left'].register_axis(self.yaxis) - self.spines['right'].register_axis(self.yaxis) + self.spines['left'].register_axis(self.yaxis, _init=True) + self.spines['right'].register_axis(self.yaxis, _init=True) self._update_transScale() def set_figure(self, fig): diff --git a/lib/matplotlib/spines.py b/lib/matplotlib/spines.py index c6b04fe43dba..1026c7c3a518 100644 --- a/lib/matplotlib/spines.py +++ b/lib/matplotlib/spines.py @@ -151,7 +151,7 @@ def _ensure_position_is_set(self): self._position = ('outward', 0.0) # in points self.set_position(self._position) - def register_axis(self, axis): + def register_axis(self, axis, _init=False): """register an axis An axis should be registered with its corresponding spine from @@ -159,7 +159,9 @@ def register_axis(self, axis): properties when needed. """ self.axis = axis - if self.axis is not None: + if not _init and self.axis is not None: + # Clear the axis when added, but *not* if the caller says it was + # just created. self.axis.cla() self.stale = True From 4801cbcda23fb019a43b6ddc03cf343b54f572a9 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 16 May 2017 02:18:26 -0400 Subject: [PATCH 3/3] Skip extra Axis.cla in PolarAxes.__init__ also. --- lib/matplotlib/projections/polar.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index a5d2b03c34b5..9976dfbe0c6b 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -245,8 +245,10 @@ def __init__(self, *args, **kwargs): If you need to interpolate data points, consider running cbook.simple_linear_interpolation on the data before passing to matplotlib.""") Axes.__init__(self, *args, **kwargs) + self._in_init = True self.set_aspect('equal', adjustable='box', anchor='C') self.cla() + self._in_init = False __init__.__doc__ = Axes.__init__.__doc__ def cla(self): 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