@@ -221,7 +221,7 @@ def too_close(self, x,y, lw):
221221 if self .cl_xy != []:
222222 dist = [sqrt ((x - loc [0 ]) ** 2 + (y - loc [1 ]) ** 2 ) for loc in self .cl_xy ]
223223 for d in dist :
224- if d < 150 :
224+ if d < 1.2 * lw :
225225 return 1
226226 else : return 0
227227 else : return 0
@@ -292,16 +292,29 @@ def break_linecontour(self, linecontour, rot, labelwidth, ind):
292292 xx = array (slc )[:,0 ].copy ()
293293 yy = array (slc )[:,1 ].copy ()
294294
295+ #indices which are under the label
295296 inds = nonzero (((xx < x + xlabel ) & (xx > x - xlabel )) & ((yy < y + ylabel ) & (yy > y - ylabel )))
296297
297298 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+
300314 else :
301315 lc1 = linecontour [:ind ]
302316 lc2 = linecontour [ind + 1 :]
303317
304- epsilon = .000005
305318
306319 if rot < 0 :
307320 new_x1 , new_y1 = x - xlabel , y + ylabel
@@ -371,7 +384,6 @@ def inline_labels(self, levels, contours, colors, fslist, fmt):
371384 trans = self .ax .transData
372385 contourNum = 0
373386 for lev , con , color , fsize in zip (levels , contours , colors , fslist ):
374- col = []
375387 toremove = []
376388 toadd = []
377389 lw = self .get_label_width (lev , fmt , fsize )
@@ -394,7 +406,6 @@ def inline_labels(self, levels, contours, colors, fslist, fmt):
394406 self .set_label_props (t , text , color )
395407 self .cl .append (t )
396408 new = self .break_linecontour (linecontour , rotation , lw , ind )
397- for c in new : col .append (c )
398409
399410 for c in new : toadd .append (c )
400411 toremove .append (linecontour )
@@ -539,8 +550,10 @@ def _contour_args(self, filled, badmask, origin, extent, *args):
539550 lev = array ([float (fl ) for fl in level_arg ])
540551 else :
541552 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 )))
544557 return (x , y , z , lev )
545558
546559
@@ -707,6 +720,7 @@ def contour(self, *args, **kwargs):
707720 if extent is not None : assert (len (extent ) == 4 )
708721 if colors is not None and cmap is not None :
709722 raise RuntimeError ('Either colors or cmap must be None' )
723+ # todo: shouldn't this use the current image rather than the rc param?
710724 if origin == 'image' : origin = rcParams ['image.origin' ]
711725
712726
@@ -727,9 +741,8 @@ def contour(self, *args, **kwargs):
727741
728742 reg , triangle = self ._initialize_reg_tri (z , badmask )
729743
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 )
733746
734747 if linewidths == None :
735748 tlinewidths = [rcParams ['lines.linewidth' ]] * Nlev
@@ -760,6 +773,8 @@ def contour(self, *args, **kwargs):
760773 collections .append (col )
761774
762775 collections = silent_list ('LineCollection' , collections )
776+ # the mappable attr is for the pylab interface functions,
777+ # which maintain the current image
763778 collections .mappable = mappable
764779 return lev , collections
765780
0 commit comments