From f0f5563a277e28f46d1d39e3eeddd86b2964aca6 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Wed, 6 Mar 2019 20:52:26 -0800 Subject: [PATCH 1/4] FIX: polar get_window_extent from spine --- examples/lines_bars_and_markers/markevery_demo.py | 5 +++-- lib/matplotlib/spines.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/lines_bars_and_markers/markevery_demo.py b/examples/lines_bars_and_markers/markevery_demo.py index 62eda10de3bc..3776794488dc 100644 --- a/examples/lines_bars_and_markers/markevery_demo.py +++ b/examples/lines_bars_and_markers/markevery_demo.py @@ -95,14 +95,15 @@ ############################################################################### # Plot each markevery case for polar plots -fig4 = plt.figure(num=4, figsize=figsize) +fig4 = plt.figure(num=4, figsize=figsize, constrained_layout=True) axpolar = [] +gs = fig4.add_gridspec(len(cases) // cols + 1, cols) for i, case in enumerate(cases): row = (i // cols) col = i % cols axpolar.append(fig4.add_subplot(gs[row, col], projection='polar')) axpolar[-1].set_title('markevery=%s' % str(case)) axpolar[-1].plot(theta, r, 'o', ls='-', ms=4, markevery=case) -fig4.tight_layout() +#fig4.tight_layout() plt.show() diff --git a/lib/matplotlib/spines.py b/lib/matplotlib/spines.py index 042bf84d4bfc..a20e71bc5448 100644 --- a/lib/matplotlib/spines.py +++ b/lib/matplotlib/spines.py @@ -159,6 +159,8 @@ def get_window_extent(self, renderer=None): # correct: self._adjust_location() bb = super().get_window_extent(renderer=renderer) + if self.axis is None: + return bb bboxes = [bb] tickstocheck = [self.axis.majorTicks[0]] if len(self.axis.minorTicks) > 1: From 0f86891195f6233285d6df27a1e663c6e318d179 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Fri, 8 Mar 2019 21:02:45 -0800 Subject: [PATCH 2/4] FIX: fix the scatter autolim issue --- lib/matplotlib/axes/_axes.py | 2 ++ lib/matplotlib/collections.py | 28 ++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index affc329f1be0..ac62f2cd37ef 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4478,6 +4478,8 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, if self._ymargin < 0.05 and x.size > 0: self.set_ymargin(0.05) + self.update_datalim(collection.get_datalim_simple(self.transData)) + self.autoscale_view() self.add_collection(collection) self.autoscale_view() diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 53df43a41a45..752c4ec3ab2e 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -178,19 +178,40 @@ def get_offset_transform(self): t = t._as_mpl_transform(self.axes) return t + def get_datalim_simple(self, transData): + offsets = self._offsets + transOffset = self.get_offset_transform() + offsets = transOffset.transform(offsets) + minx = np.Inf + maxx = -np.Inf + miny = np.Inf + maxy = -np.Inf + for off in offsets: + x = off[0] + y = off[1] + if x < minx: + minx = x + if x > maxx: + maxx = x + if y < miny: + miny = y + if y > maxy: + maxy = y + bb = transforms.Bbox([[minx, miny], [maxx, maxy]]) + return bb.inverse_transformed(transData) + + def get_datalim(self, transData): transform = self.get_transform() transOffset = self.get_offset_transform() offsets = self._offsets paths = self.get_paths() - if not transform.is_affine: paths = [transform.transform_path_non_affine(p) for p in paths] transform = transform.get_affine() if not transOffset.is_affine: offsets = transOffset.transform_non_affine(offsets) transOffset = transOffset.get_affine() - if isinstance(offsets, np.ma.MaskedArray): offsets = offsets.filled(np.nan) # get_path_collection_extents handles nan but not masked arrays @@ -365,6 +386,9 @@ def contains(self, mouseevent): self._picker is not True # the bool, not just nonzero or 1 else self._pickradius) + if self.axes and self.get_offset_position() == "data": + self.axes._unstale_viewLim() + transform, transOffset, offsets, paths = self._prepare_points() ind = _path.point_in_path_collection( From 4d2d4c0c77f32c329d377173c679fc2feff972da Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Fri, 8 Mar 2019 21:15:02 -0800 Subject: [PATCH 3/4] FIX: fix the scatter autolim issue --- examples/lines_bars_and_markers/markevery_demo.py | 5 ++--- lib/matplotlib/spines.py | 2 -- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/lines_bars_and_markers/markevery_demo.py b/examples/lines_bars_and_markers/markevery_demo.py index 3776794488dc..62eda10de3bc 100644 --- a/examples/lines_bars_and_markers/markevery_demo.py +++ b/examples/lines_bars_and_markers/markevery_demo.py @@ -95,15 +95,14 @@ ############################################################################### # Plot each markevery case for polar plots -fig4 = plt.figure(num=4, figsize=figsize, constrained_layout=True) +fig4 = plt.figure(num=4, figsize=figsize) axpolar = [] -gs = fig4.add_gridspec(len(cases) // cols + 1, cols) for i, case in enumerate(cases): row = (i // cols) col = i % cols axpolar.append(fig4.add_subplot(gs[row, col], projection='polar')) axpolar[-1].set_title('markevery=%s' % str(case)) axpolar[-1].plot(theta, r, 'o', ls='-', ms=4, markevery=case) -#fig4.tight_layout() +fig4.tight_layout() plt.show() diff --git a/lib/matplotlib/spines.py b/lib/matplotlib/spines.py index a20e71bc5448..042bf84d4bfc 100644 --- a/lib/matplotlib/spines.py +++ b/lib/matplotlib/spines.py @@ -159,8 +159,6 @@ def get_window_extent(self, renderer=None): # correct: self._adjust_location() bb = super().get_window_extent(renderer=renderer) - if self.axis is None: - return bb bboxes = [bb] tickstocheck = [self.axis.majorTicks[0]] if len(self.axis.minorTicks) > 1: From 2ade42cb07cb6eaba170426377ada9a3d3261d60 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Fri, 8 Mar 2019 21:40:07 -0800 Subject: [PATCH 4/4] FIX: fix the scatter autolim issue --- lib/matplotlib/collections.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 752c4ec3ab2e..54c09853998b 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -181,22 +181,11 @@ def get_offset_transform(self): def get_datalim_simple(self, transData): offsets = self._offsets transOffset = self.get_offset_transform() - offsets = transOffset.transform(offsets) - minx = np.Inf - maxx = -np.Inf - miny = np.Inf - maxy = -np.Inf - for off in offsets: - x = off[0] - y = off[1] - if x < minx: - minx = x - if x > maxx: - maxx = x - if y < miny: - miny = y - if y > maxy: - maxy = y + offsets = np.asarray(transOffset.transform(offsets)) + minx = offsets[:, 0].min() + maxx = offsets[:, 0].max() + miny = offsets[:, 1].min() + maxy = offsets[:, 1].max() bb = transforms.Bbox([[minx, miny], [maxx, maxy]]) return bb.inverse_transformed(transData) 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