Skip to content
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

add get_segments method to collections.LineCollection - updated #1645

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/matplotlib/collections.py
Expand Up @@ -1008,6 +1008,19 @@ def set_segments(self, segments):
set_verts = set_segments # for compatibility with PolyCollection
set_paths = set_segments

def get_segments(self):
_segments = []
Copy link
Member

Choose a reason for hiding this comment

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

there is no real benefit to prefixing these variables with an underscore (they are out of scope in all but this method). Would you mind de-underscoring them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On Wed, Jan 9, 2013 at 11:47 AM, Phil Elson notifications@github.comwrote:

In lib/matplotlib/collections.py:

@@ -1008,6 +1008,19 @@ def set_segments(self, segments):
set_verts = set_segments # for compatibility with PolyCollection
set_paths = set_segments

  • def get_segments(self):
  •    _segments = []
    

there is no real benefit to prefixing these variables with an underscore
(they are out of scope in all but this method). Would you mind
de-underscoring them?


Reply to this email directly or view it on GitHubhttps://github.com//pull/1645/files#r2588408.

I would not mind at all. However, I was trying to keep the same variable
naming scheme as set_segments. Either way is fine with me.


for path in self._paths:
_vertices = [vertex for vertex, _ in path.iter_segments()]
_vertices = np.asarray(_vertices)
_segments.append(_vertices)

return _segments

get_verts = get_segments
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs to be considered, strictly speaking you're not getting the vertices, you're getting the paths. I appreciate that there is a setter defined further up which allows you to set_verts with a list of paths, so perhaps we should just add the same comment as on line 1008...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On Wed, Jan 9, 2013 at 11:49 AM, Phil Elson notifications@github.comwrote:

In lib/matplotlib/collections.py:

@@ -1008,6 +1008,19 @@ def set_segments(self, segments):
set_verts = set_segments # for compatibility with PolyCollection
set_paths = set_segments

  • def get_segments(self):
  •    _segments = []
    
  •    for path in self._paths:
    
  •        _vertices = [vertex for vertex, _ in path.iter_segments()]
    
  •        _vertices = np.asarray(_vertices)
    
  •        _segments.append(_vertices)
    
  •    return _segments
    
  • get_verts = get_segments

I think this needs to be considered, strictly speaking you're not getting
the vertices, you're getting the paths. I appreciate that there is a setter
defined further up which allows you to set_verts with a list of paths, so
perhaps we should just add the same comment as on line 1008...

Yes, you are right, I should have added that comment. I don't know why I
didn't.

get_paths = get_segments

def _add_offsets(self, segs):
offsets = self._uniform_offsets
Nsegs = len(segs)
Expand Down