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

Skip to content

Commit 56ef1a8

Browse files
committed
added some test cases for legend
svn path=/trunk/matplotlib/; revision=3169
1 parent a5bf967 commit 56ef1a8

4 files changed

Lines changed: 37 additions & 4 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,11 +2358,15 @@ def vlines(self, x, ymin, ymax, colors='k', linestyle='solid', **kwargs):
23582358
determined by ymin and ymax
23592359
23602360
2361-
colors is a line collections color args, either a single color or a len(x) list of colors
2361+
colors is a line collections color args, either a single color
2362+
or a len(x) list of colors
23622363
23632364
linestyle is one of solid|dashed|dashdot|dotted
23642365
23652366
Returns the LineCollection that was added
2367+
2368+
kwargs are LineCollection properties:
2369+
%(LineCollection)s
23662370
"""
23672371

23682372
if kwargs.get('fmt') is not None:
@@ -2393,7 +2397,7 @@ def vlines(self, x, ymin, ymax, colors='k', linestyle='solid', **kwargs):
23932397
verts = [ ((thisx, thisymin), (thisx, thisymax)) for thisx, (thisymin, thisymax) in zip(x,Y)]
23942398
coll = LineCollection(verts, colors=colors, linestyle=linestyle)
23952399
self.add_collection(coll)
2396-
2400+
coll.update(kwargs)
23972401

23982402
minx = nx.amin(x)
23992403
maxx = nx.amax(x)
@@ -2404,7 +2408,7 @@ def vlines(self, x, ymin, ymax, colors='k', linestyle='solid', **kwargs):
24042408
self.autoscale_view()
24052409

24062410
return coll
2407-
vlines.__doc__ = dedent(vlines.__doc__)
2411+
vlines.__doc__ = dedent(vlines.__doc__) % artist.kwdocd
24082412

24092413
#### Basic plotting
24102414
def plot(self, *args, **kwargs):

lib/matplotlib/collections.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,20 @@ def get_transoffset(self):
647647
return self._transOffset
648648

649649
def set_segments(self, segments):
650+
"""
651+
set the line segments
652+
653+
ACCEPTS: a list of [(x1,y1), (x2, x2)...] segments
654+
"""
650655
if segments is None: return
651656
self._segments = [asarray(seg) for seg in segments]
652657
if self._uniform_offsets is not None:
653658
self._add_offsets()
654659

660+
def get_segments(self):
661+
'get the line segments'
662+
return self._segments
663+
655664
set_verts = set_segments # for compatibility with PolyCollection
656665

657666
def _add_offsets(self):

lib/matplotlib/legend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def get_handles(ax):
328328

329329
inv = ax.transAxes.inverse_xy_tup
330330
for handle in handles:
331-
331+
print 'autolegend', handle, type(handle)
332332
if isinstance(handle, Line2D):
333333

334334
xdata = handle.get_xdata(orig=False)

unit/legend_unit.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from pylab import figure, show, nx
2+
3+
# scatter creates a RegPolyCollection
4+
fig = figure()
5+
ax = fig.add_subplot(111)
6+
N = 100
7+
x, y = 0.9*nx.mlab.rand(2,N)
8+
area = nx.pi*(10 * nx.mlab.rand(N))**2 # 0 to 10 point radiuses
9+
ax.scatter(x,y,s=area, marker='^', c='r', label='scatter')
10+
ax.legend()
11+
fig.savefig('legend_unit_polycoll')
12+
13+
# vlines creates a LineCollection
14+
fig = figure()
15+
ax = fig.add_subplot(111)
16+
t = nx.arange(0.0, 1.0, 0.05)
17+
ax.vlines(t, [0], nx.sin(2*nx.pi*t), label='vlines')
18+
ax.legend()
19+
fig.savefig('legend_unit_linecoll')
20+
show()

0 commit comments

Comments
 (0)