Skip to content

Bug Fix - Polar plot rectangle patch not transformed correctly (#8521) #10488

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 7 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
13 changes: 13 additions & 0 deletions lib/matplotlib/projections/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,19 @@ def __init__(self, *args, **kwargs):
self.cla()
__init__.__doc__ = Axes.__init__.__doc__

def add_patch(self, patch):
"""
Override the existing add_patch() method from _AxesBase class.
The _interpolation_steps field should be revised prior to drawing.

:param patch: `~matplotlib.patches.Patch`
:return: `~matplotlib.patches.Patch`
"""
patch.get_path()._interpolation_steps = \
max(patch.get_path()._interpolation_steps, # default 1
maxis.GRIDLINE_INTERPOLATION_STEPS) # 180
return super().add_patch(patch)

def cla(self):
Axes.cla(self)

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,17 @@ def test_connection_patch():
ax2.add_artist(con)


@image_comparison(baseline_images=['transform_rectangle'], extensions=['png'],
style='mpl20', remove_text=True)
def test_polar_rectangle_transform_patch():
# Rectangle patch not transformed correctly in polar plot (#8521)
rectangle = mpatches.Rectangle((0, 1), width=np.pi * 0.5, height=1)
fig = plt.figure(figsize=(6, 8))
ax = fig.add_subplot(1, 1, 1, polar=True)
ax.add_patch(rectangle)
ax.set_rmax(2.5)


def test_datetime_rectangle():
# Check that creating a rectangle with timedeltas doesn't fail
from datetime import datetime, timedelta
Expand Down