Skip to content

Commit 3798e5f

Browse files
authored
Merge pull request #19088 from jsberg-bnl/issue-19078
Ignore CLOSEPOLY vertices when computing dataLim from patches
2 parents 51ab42c + 039e416 commit 3798e5f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/matplotlib/axes/_base.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import matplotlib.font_manager as font_manager
2626
import matplotlib.text as mtext
2727
import matplotlib.image as mimage
28+
import matplotlib.path as mpath
2829
from matplotlib.rcsetup import cycler, validate_axisbelow
2930

3031
_log = logging.getLogger(__name__)
@@ -2094,7 +2095,9 @@ def _update_patch_limits(self, patch):
20942095
if (isinstance(patch, mpatches.Rectangle) and
20952096
((not patch.get_width()) and (not patch.get_height()))):
20962097
return
2097-
vertices = patch.get_path().vertices
2098+
p = patch.get_path()
2099+
vertices = p.vertices if p.codes is None else p.vertices[np.isin(
2100+
p.codes, (mpath.Path.CLOSEPOLY, mpath.Path.STOP), invert=True)]
20982101
if vertices.size > 0:
20992102
xys = patch.get_patch_transform().transform(vertices)
21002103
if patch.get_data_transform() != self.transData:

lib/matplotlib/tests/test_axes.py

+8
Original file line numberDiff line numberDiff line change
@@ -6924,3 +6924,11 @@ def test_bar_label_labels():
69246924
labels = ax.bar_label(rects, labels=['A', 'B'])
69256925
assert labels[0].get_text() == 'A'
69266926
assert labels[1].get_text() == 'B'
6927+
6928+
6929+
def test_patch_bounds(): # PR 19078
6930+
fig, ax = plt.subplots()
6931+
ax.add_patch(mpatches.Wedge((0, -1), 1.05, 60, 120, 0.1))
6932+
bot = 1.9*np.sin(15*np.pi/180)**2
6933+
np.testing.assert_array_almost_equal_nulp(
6934+
np.array((-0.525, -(bot+0.05), 1.05, bot+0.1)), ax.dataLim.bounds, 16)

0 commit comments

Comments
 (0)