Skip to content

Re-cache Line2D path when transform changed #24817

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ def __init__(self, xdata, ydata, *,
self._xy = None
self._path = None
self._transformed_path = None
self._transform_when_path_transformed = None
self._subslice = False
self._x_filled = None # used in subslicing; only x is needed

Expand Down Expand Up @@ -721,6 +722,7 @@ def _transform_path(self, subslice=None):
_interpolation_steps=self._path._interpolation_steps)
else:
_path = self._path
self._transform_when_path_transformed = self.get_transform().frozen()
self._transformed_path = TransformedPath(_path, self.get_transform())

def _get_transformed_path(self):
Expand All @@ -742,7 +744,7 @@ def draw(self, renderer):
if not self.get_visible():
return

if self._invalidy or self._invalidx:
if self._invalidy or self._invalidx or self.get_transform() != self._transform_when_path_transformed:
self.recache()
self.ind_offset = 0 # Needed for contains() method.
if self._subslice and self.axes:
Expand Down
24 changes: 24 additions & 0 deletions lib/matplotlib/tests/test_polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,27 @@ def test_polar_neg_theta_lims():
ax.set_thetalim(-np.pi, np.pi)
labels = [l.get_text() for l in ax.xaxis.get_ticklabels()]
assert labels == ['-180°', '-135°', '-90°', '-45°', '0°', '45°', '90°', '135°']


@check_figures_equal(extensions=["png"])
def test_polar_lim_draw(fig_test, fig_ref):
"""
Check that lines on polar axes are correctly transformed after
a draw and an axes limit change.

"""
# A quarter arc at r=5
theta = np.linspace(0, np.pi/2, 90)
r = np.full(90, 5)

ax_ref = fig_ref.add_subplot(projection='polar')
ax_ref.set_ylim(0, 10)
ax_ref.plot(theta, r)

ax_test = fig_test.add_subplot(projection='polar')
ax_test.set_ylim(4, 10)

ax_test.plot(theta, r)
fig_test.canvas.draw()

ax_test.set_ylim(0, 10)