-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Use Path.arc() to interpolate polar arcs. #14852
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
import matplotlib.axis as maxis | ||
import matplotlib.markers as mmarkers | ||
import matplotlib.patches as mpatches | ||
import matplotlib.path as mpath | ||
from matplotlib.path import Path | ||
import matplotlib.ticker as mticker | ||
import matplotlib.transforms as mtransforms | ||
import matplotlib.spines as mspines | ||
|
@@ -50,11 +50,57 @@ def transform_non_affine(self, tr): | |
|
||
def transform_path_non_affine(self, path): | ||
# docstring inherited | ||
vertices = path.vertices | ||
if len(vertices) == 2 and vertices[0, 0] == vertices[1, 0]: | ||
return mpath.Path(self.transform(vertices), path.codes) | ||
ipath = path.interpolated(path._interpolation_steps) | ||
return mpath.Path(self.transform(ipath.vertices), ipath.codes) | ||
if not len(path) or path._interpolation_steps == 1: | ||
return Path(self.transform_non_affine(path.vertices), path.codes) | ||
xys = [] | ||
codes = [] | ||
last_t = last_r = None | ||
for trs, c in path.iter_segments(): | ||
trs = trs.reshape((-1, 2)) | ||
if c == Path.LINETO: | ||
(t, r), = trs | ||
if t == last_t: # Same angle: draw a straight line. | ||
xys.extend(self.transform_non_affine(trs)) | ||
codes.append(Path.LINETO) | ||
elif r == last_r: # Same radius: draw an arc. | ||
# The following is complicated by Path.arc() being | ||
# "helpful" and unwrapping the angles, but we don't want | ||
# that behavior here. | ||
last_td, td = np.rad2deg([last_t, t]) | ||
if self._use_rmin and self._axis is not None: | ||
r = ((r - self._axis.get_rorigin()) | ||
* self._axis.get_rsign()) | ||
if last_td <= td: | ||
while td - last_td > 360: | ||
arc = Path.arc(last_td, last_td + 360) | ||
xys.extend(arc.vertices[1:] * r) | ||
codes.extend(arc.codes[1:]) | ||
last_td += 360 | ||
arc = Path.arc(last_td, td) | ||
xys.extend(arc.vertices[1:] * r) | ||
codes.extend(arc.codes[1:]) | ||
else: | ||
# The reverse version also relies on the fact that all | ||
# codes but the first one are the same. | ||
while last_td - td > 360: | ||
arc = Path.arc(last_td - 360, last_td) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As does this block. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
xys.extend(arc.vertices[::-1][1:] * r) | ||
codes.extend(arc.codes[1:]) | ||
last_td -= 360 | ||
arc = Path.arc(td, last_td) | ||
xys.extend(arc.vertices[::-1][1:] * r) | ||
codes.extend(arc.codes[1:]) | ||
else: # Interpolate. | ||
trs = cbook.simple_linear_interpolation( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this block too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test added |
||
np.row_stack([(last_t, last_r), trs]), | ||
path._interpolation_steps)[1:] | ||
xys.extend(self.transform_non_affine(trs)) | ||
codes.extend([Path.LINETO] * len(trs)) | ||
else: # Not a straight line. | ||
xys.extend(self.transform_non_affine(trs)) | ||
codes.extend([c] * len(trs)) | ||
last_t, last_r = trs[-1] | ||
return Path(xys, codes) | ||
|
||
def inverted(self): | ||
# docstring inherited | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block seems untested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test added, although it's not particularly interesting (I can't actually think of a very interesting test for that...)