Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Ignore CLOSEPOLY vertices when computing dataLim from patches #19088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)