Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a5bf967

Browse files
committed
Fixed legend and LineCollection to work together again
svn path=/trunk/matplotlib/; revision=3168
1 parent 01bdca7 commit a5bf967

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2007-04-07 Fixed legend/LineCollection bug. - EF
2+
13
2007-04-06 Removed deprecated support for a float value as a gray-scale;
24
now it must be a string, like '0.5'. Added alpha kwarg to
35
ColorConverter.to_rgba_list. - EF

lib/matplotlib/collections.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,24 @@ def get_verts(self, dataTrans=None):
779779
raise NotImplementedError('Vertices in data coordinates are calculated\n'
780780
+ 'with offsets only if _transOffset == dataTrans.')
781781

782+
def get_lines(self):
783+
'return seq of lines in collection'
784+
# This is needed for legend, even though it is incomplete,
785+
# like get_verts, and essentially wrong in general.
786+
# We could add a check for validity as in get_verts.
787+
if self._offsets is None:
788+
offsets = [(0,0)]
789+
else:
790+
offsets = self._offsets
791+
Noffsets = len(offsets)
792+
Nsegments = len(self._segments)
793+
lines = []
794+
for i in range(max(Noffsets, Nsegments)):
795+
ox, oy = offsets[i%Noffsets]
796+
segment = self._segments[i%Nsegments]
797+
lines.append([(x+ox, y+oy) for x,y in segment])
798+
return lines
799+
782800
def update_scalarmappable(self):
783801
"""
784802
If the scalar mappable array is not none, update colors

lib/matplotlib/legend.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def line_cuts_bbox(line, bbox):
5252

5353
if n == 1:
5454
return bbox.contains(line[0][0], line[0][1])
55-
5655
p1 = line[0]
5756
for p2 in line[1:]:
5857
segment = (p1, p2)
@@ -359,7 +358,7 @@ def get_handles(ax):
359358
for line in hlines:
360359
tline = trans.seq_xy_tups(line)
361360
aline = [inv(v) for v in tline]
362-
lines.extend(line)
361+
lines.append(aline)
363362

364363
return [vertices, bboxes, lines]
365364

0 commit comments

Comments
 (0)