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

Skip to content

Ignore closepoly vertices in _update_patch_limits. #19159

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

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 3 additions & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2094,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
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:
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -6856,3 +6858,15 @@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use numpy for these rather than importing math? You may also want to look at np.testing.assert_allclose rather than writing your own tolerance.

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