diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index c6309b5ab9df..f2b5d1ee7143 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -25,6 +25,7 @@ import matplotlib.font_manager as font_manager import matplotlib.text as mtext import matplotlib.image as mimage +import matplotlib.path as mpath from matplotlib.rcsetup import cycler, validate_axisbelow _log = logging.getLogger(__name__) @@ -2094,7 +2095,9 @@ 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 + p = patch.get_path() + vertices = p.vertices if p.codes is None else p.vertices[np.isin( + p.codes, (mpath.Path.CLOSEPOLY, mpath.Path.STOP), invert=True)] if vertices.size > 0: xys = patch.get_patch_transform().transform(vertices) if patch.get_data_transform() != self.transData: diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 9d7722648183..e9d5fb623e62 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -6924,3 +6924,11 @@ def test_bar_label_labels(): labels = ax.bar_label(rects, labels=['A', 'B']) assert labels[0].get_text() == 'A' assert labels[1].get_text() == 'B' + + +def test_patch_bounds(): # PR 19078 + fig, ax = plt.subplots() + ax.add_patch(mpatches.Wedge((0, -1), 1.05, 60, 120, 0.1)) + bot = 1.9*np.sin(15*np.pi/180)**2 + np.testing.assert_array_almost_equal_nulp( + np.array((-0.525, -(bot+0.05), 1.05, bot+0.1)), ax.dataLim.bounds, 16)