From dd7c59ba9bb006e4836408b9dd5333ffb5197cd2 Mon Sep 17 00:00:00 2001 From: Arun12121 Date: Mon, 21 Dec 2020 00:11:12 +0530 Subject: [PATCH 1/5] Updated patch imits to ignore CLOSEPOLY vertices --- lib/matplotlib/axes/_base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index c6309b5ab9df..3124716ae34b 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -17,6 +17,7 @@ import matplotlib.colors as mcolors import matplotlib.lines as mlines import matplotlib.patches as mpatches +import matplotlib.path as mpath import matplotlib.artist as martist import matplotlib.transforms as mtransforms import matplotlib.ticker as mticker @@ -2094,7 +2095,7 @@ def _update_patch_limits(self, patch): if (isinstance(patch, mpatches.Rectangle) and ((not patch.get_width()) and (not patch.get_height()))): return - vertices = patch.get_path().vertices + vertices = patch.get_path().vertices[patch.get_path().codes != mpath.Path.CLOSEPOLY] if vertices.size > 0: xys = patch.get_patch_transform().transform(vertices) if patch.get_data_transform() != self.transData: From 44e840edca54c13692b599aa4fd4f74b210aa178 Mon Sep 17 00:00:00 2001 From: Arun12121 Date: Mon, 21 Dec 2020 00:21:30 +0530 Subject: [PATCH 2/5] Added tests from PR#19078 --- lib/matplotlib/tests/test_axes.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 56f45518c340..7b136a51f51b 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -34,6 +34,8 @@ assert_allclose, assert_array_equal, assert_array_almost_equal) from matplotlib import rc_context from matplotlib.cbook import MatplotlibDeprecationWarning +import sys +import math # Note: Some test cases are run twice: once normally and once with labeled data # These two must be defined in the same test function or need to have @@ -6856,3 +6858,14 @@ def test_ylabel_ha_with_position(ha): ax.set_ylabel("test", y=1, ha=ha) ax.yaxis.set_label_position("right") assert ax.yaxis.get_label().get_ha() == ha + +def test_patch_bounds(): + fig, ax = plt.subplots() + tol = 16*sys.float_info.epsilon + ax.add_patch(mpatches.Wedge((0, -1), 1.05, 60, 120, 0.1)) + bounds = ax.dataLim.bounds + bot = 1.9*math.sin(15*math.pi/180)**2 + assert abs(bounds[0]+0.525) < tol and \ + abs(bounds[1]+(bot+0.05)) < tol and \ + abs(bounds[2]-1.05) < tol and \ + abs(bounds[3]-(bot+0.1)) < tol From 0f49935d5d161b985d3c3f63f2ee223a49a9bd54 Mon Sep 17 00:00:00 2001 From: Arun12121 Date: Mon, 21 Dec 2020 00:35:37 +0530 Subject: [PATCH 3/5] Correct some formatting --- lib/matplotlib/tests/test_axes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 7b136a51f51b..1ff1a857da41 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -6859,6 +6859,7 @@ def test_ylabel_ha_with_position(ha): ax.yaxis.set_label_position("right") assert ax.yaxis.get_label().get_ha() == ha + def test_patch_bounds(): fig, ax = plt.subplots() tol = 16*sys.float_info.epsilon From 9196d9a6b49d0716e6fee484cbcb39fd27e4a078 Mon Sep 17 00:00:00 2001 From: Arun12121 Date: Mon, 21 Dec 2020 23:27:19 +0530 Subject: [PATCH 4/5] Split line 2098 for flake8 --- lib/matplotlib/axes/_base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 3124716ae34b..a7932efb3b0a 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2095,7 +2095,8 @@ def _update_patch_limits(self, patch): if (isinstance(patch, mpatches.Rectangle) and ((not patch.get_width()) and (not patch.get_height()))): return - vertices = patch.get_path().vertices[patch.get_path().codes != mpath.Path.CLOSEPOLY] + vertices = patch.get_path().vertices[patch.\ + get_path().codes != mpath.Path.CLOSEPOLY] if vertices.size > 0: xys = patch.get_patch_transform().transform(vertices) if patch.get_data_transform() != self.transData: From 5ff85abbfb65394e7c62ce9f831e62814df2f838 Mon Sep 17 00:00:00 2001 From: Arun12121 Date: Mon, 21 Dec 2020 23:35:27 +0530 Subject: [PATCH 5/5] Corrected more flake8 errors --- lib/matplotlib/axes/_base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index a7932efb3b0a..33f348d646d4 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2095,8 +2095,8 @@ def _update_patch_limits(self, patch): if (isinstance(patch, mpatches.Rectangle) and ((not patch.get_width()) and (not patch.get_height()))): return - vertices = patch.get_path().vertices[patch.\ - get_path().codes != mpath.Path.CLOSEPOLY] + vertices = patch.get_path().\ + vertices[patch.get_path().codes != mpath.Path.CLOSEPOLY] if vertices.size > 0: xys = patch.get_patch_transform().transform(vertices) if patch.get_data_transform() != self.transData: