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

Skip to content

Commit e8f4297

Browse files
committed
Simplified internal code of _auto_legend_data
svn path=/trunk/matplotlib/; revision=3370
1 parent 5027a6c commit e8f4297

2 files changed

Lines changed: 22 additions & 26 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2007-06-07 Simplified internal code of _auto_legend_data - NN
2+
13
2007-06-04 Added labeldistance arg to Axes.pie to control the raidal
24
distance of the wedge labels - JDH
35

lib/matplotlib/legend.py

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -313,46 +313,40 @@ def _auto_legend_data(self):
313313
if not self.isaxes:
314314
raise Exception, 'Auto legends not available for figure legends.'
315315

316-
def get_handles(ax):
317-
handles = ax.lines[:]
318-
handles.extend(ax.patches)
319-
handles.extend([c for c in ax.collections if isinstance(c, LineCollection)])
320-
321-
return handles
322-
323316
ax = self.parent
324-
handles = get_handles(ax)
325317
vertices = []
326318
bboxes = []
327319
lines = []
328320

329321
inv = ax.transAxes.inverse_xy_tup
330-
for handle in handles:
331322

332-
if isinstance(handle, Line2D):
323+
for handle in ax.lines:
324+
assert isinstance(handle, Line2D)
333325

334-
xdata = handle.get_xdata(orig=False)
335-
ydata = handle.get_ydata(orig=False)
336-
trans = handle.get_transform()
337-
xt, yt = trans.numerix_x_y(xdata, ydata)
326+
xdata = handle.get_xdata(orig=False)
327+
ydata = handle.get_ydata(orig=False)
328+
trans = handle.get_transform()
329+
xt, yt = trans.numerix_x_y(xdata, ydata)
338330

339-
# XXX need a special method in transform to do a list of verts
340-
averts = [inv(v) for v in zip(xt, yt)]
341-
lines.append(averts)
331+
# XXX need a special method in transform to do a list of verts
332+
averts = [inv(v) for v in zip(xt, yt)]
333+
lines.append(averts)
342334

343-
elif isinstance(handle, Patch):
335+
for handle in ax.patches:
336+
assert isinstance(handle, Patch)
344337

345-
verts = handle.get_verts()
346-
trans = handle.get_transform()
347-
tverts = trans.seq_xy_tups(verts)
338+
verts = handle.get_verts()
339+
trans = handle.get_transform()
340+
tverts = trans.seq_xy_tups(verts)
348341

349-
averts = [inv(v) for v in tverts]
342+
averts = [inv(v) for v in tverts]
350343

351-
bbox = unit_bbox()
352-
bbox.update(averts, True)
353-
bboxes.append(bbox)
344+
bbox = unit_bbox()
345+
bbox.update(averts, True)
346+
bboxes.append(bbox)
354347

355-
elif isinstance(handle, LineCollection):
348+
for handle in ax.collections:
349+
if isinstance(handle, LineCollection):
356350
hlines = handle.get_lines()
357351
trans = handle.get_transform()
358352
for line in hlines:

0 commit comments

Comments
 (0)