FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Use Path.arc() to interpolate polar arcs. by anntzer · Pull Request #14852 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .pdf  (8) .png  (11) .py  (2) .svg  (8) All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
58 changes: 52 additions & 6 deletions lib/matplotlib/projections/polar.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This block seems untested.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

test added, although it's not particularly interesting (I can't actually think of a very interesting test for that...)

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

As does this block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

And this block too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
1,903 changes: 704 additions & 1,199 deletions lib/matplotlib/tests/baseline_images/test_axes/markevery_polar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading

Back | FazBrowse Home | New Git URL