add get_segments method to collections.LineCollection - updated #1645

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
Contributor

toddrjen commented Jan 8, 2013

collections.LineCollection has a set_segments method that lets you set the vertices of the line segments in the collection. However, it has no corresponding get_segments method. This adds the method.

@pelson pelson commented on the diff Jan 9, 2013

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 = []
@pelson

pelson Jan 9, 2013

Member

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?

@toddrjen

toddrjen Jan 9, 2013

Contributor

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/matplotlib/matplotlib/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.

@pelson pelson commented on the diff Jan 9, 2013

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
@pelson

pelson Jan 9, 2013

Member

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...

@toddrjen

toddrjen Jan 9, 2013

Contributor

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.

Member

pelson commented Jan 9, 2013

Thanks for doing this @toddrjen - all looks good apart from my nit-picking comments 😄

Contributor

toddrjen commented Jan 9, 2013

This pull request has been superseded by add "get_segments method to collections.LineCollection - updated"

toddrjen closed this Jan 9, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment