@@ -221,7 +221,7 @@ def too_close(self, x,y, lw):
221
221
if self .cl_xy != []:
222
222
dist = [sqrt ((x - loc [0 ]) ** 2 + (y - loc [1 ]) ** 2 ) for loc in self .cl_xy ]
223
223
for d in dist :
224
- if d < 150 :
224
+ if d < 1.2 * lw :
225
225
return 1
226
226
else : return 0
227
227
else : return 0
@@ -292,16 +292,29 @@ def break_linecontour(self, linecontour, rot, labelwidth, ind):
292
292
xx = array (slc )[:,0 ].copy ()
293
293
yy = array (slc )[:,1 ].copy ()
294
294
295
+ #indices which are under the label
295
296
inds = nonzero (((xx < x + xlabel ) & (xx > x - xlabel )) & ((yy < y + ylabel ) & (yy > y - ylabel )))
296
297
297
298
if len (inds ) > 0 :
298
- lc1 = linecontour [:inds [0 ]]
299
- lc2 = linecontour [inds [- 1 ]+ 1 :]
299
+ #if the label happens to be over the beginning of the
300
+ #contour, the entire contour is removed, i.e.
301
+ #indices to be removed are
302
+ #inds= [0,1,2,3,305,306,307]
303
+ #should rewrite this in a better way
304
+ linds = nonzero (inds [1 :]- inds [:- 1 ] != 1 )
305
+ if inds [0 ] == 0 and len (linds ) != 0 :
306
+ ii = inds [linds [0 ]]
307
+ lc1 = linecontour [ii + 1 :inds [ii + 1 ]]
308
+ lc2 = []
309
+
310
+ else :
311
+ lc1 = linecontour [:inds [0 ]]
312
+ lc2 = linecontour [inds [- 1 ]+ 1 :]
313
+
300
314
else :
301
315
lc1 = linecontour [:ind ]
302
316
lc2 = linecontour [ind + 1 :]
303
317
304
- epsilon = .000005
305
318
306
319
if rot < 0 :
307
320
new_x1 , new_y1 = x - xlabel , y + ylabel
@@ -371,7 +384,6 @@ def inline_labels(self, levels, contours, colors, fslist, fmt):
371
384
trans = self .ax .transData
372
385
contourNum = 0
373
386
for lev , con , color , fsize in zip (levels , contours , colors , fslist ):
374
- col = []
375
387
toremove = []
376
388
toadd = []
377
389
lw = self .get_label_width (lev , fmt , fsize )
@@ -394,7 +406,6 @@ def inline_labels(self, levels, contours, colors, fslist, fmt):
394
406
self .set_label_props (t , text , color )
395
407
self .cl .append (t )
396
408
new = self .break_linecontour (linecontour , rotation , lw , ind )
397
- for c in new : col .append (c )
398
409
399
410
for c in new : toadd .append (c )
400
411
toremove .append (linecontour )
@@ -539,8 +550,10 @@ def _contour_args(self, filled, badmask, origin, extent, *args):
539
550
lev = array ([float (fl ) for fl in level_arg ])
540
551
else :
541
552
raise TypeError ("Last %s arg must give levels; see help(%s)" % (fn ,fn ))
542
- self .ax .set_xlim ((min (ravel (x )), max (ravel (x ))))
543
- self .ax .set_ylim ((min (ravel (y )), max (ravel (y ))))
553
+ rx = ravel (x )
554
+ ry = ravel (y )
555
+ self .ax .set_xlim ((min (rx ), max (rx )))
556
+ self .ax .set_ylim ((min (ry ), max (ry )))
544
557
return (x , y , z , lev )
545
558
546
559
@@ -707,6 +720,7 @@ def contour(self, *args, **kwargs):
707
720
if extent is not None : assert (len (extent ) == 4 )
708
721
if colors is not None and cmap is not None :
709
722
raise RuntimeError ('Either colors or cmap must be None' )
723
+ # todo: shouldn't this use the current image rather than the rc param?
710
724
if origin == 'image' : origin = rcParams ['image.origin' ]
711
725
712
726
@@ -727,9 +741,8 @@ def contour(self, *args, **kwargs):
727
741
728
742
reg , triangle = self ._initialize_reg_tri (z , badmask )
729
743
730
- tcolors , mappable , collections = self ._process_colors (z , colors ,
731
- alpha ,
732
- lev , cmap )
744
+ tcolors , mappable , collections = self ._process_colors (
745
+ z , colors , alpha , lev , cmap )
733
746
734
747
if linewidths == None :
735
748
tlinewidths = [rcParams ['lines.linewidth' ]] * Nlev
@@ -760,6 +773,8 @@ def contour(self, *args, **kwargs):
760
773
collections .append (col )
761
774
762
775
collections = silent_list ('LineCollection' , collections )
776
+ # the mappable attr is for the pylab interface functions,
777
+ # which maintain the current image
763
778
collections .mappable = mappable
764
779
return lev , collections
765
780
0 commit comments