Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add get_segments method to collections.LineCollection - updated #1645

Closed
wants to merge 1 commit into from

2 participants

toddrjen Phil Elson
toddrjen

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.

Phil Elson pelson commented on the diff
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 = []
Phil Elson Collaborator
pelson added a note

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 added a note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Phil Elson pelson commented on the diff
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
Phil Elson Collaborator
pelson added a note

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 added a note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Phil Elson
Collaborator

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

toddrjen

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

toddrjen toddrjen closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 0 deletions.
  1. +13 −0 lib/matplotlib/collections.py
13 lib/matplotlib/collections.py
View
@@ -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 = []
Phil Elson Collaborator
pelson added a note

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 added a note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ 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
Phil Elson Collaborator
pelson added a note

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 added a note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ get_paths = get_segments
+
def _add_offsets(self, segs):
offsets = self._uniform_offsets
Nsegs = len(segs)
Something went wrong with that request. Please try again.