@@ -470,11 +470,18 @@ def _add_solids(self, X, Y, C):
470
470
def add_lines (self , levels , colors , linewidths ):
471
471
'''
472
472
Draw lines on the colorbar.
473
+
474
+ *colors* and *linewidths* must be scalars or
475
+ sequences the same length as *levels*.
473
476
'''
474
- N = len (levels )
475
- dummy , y = self ._locate (levels )
476
- if len (y ) != N :
477
- raise ValueError ("levels are outside colorbar range" )
477
+ y = self ._locate (levels )
478
+ igood = (y < 1.001 ) & (y > - 0.001 )
479
+ y = y [igood ]
480
+ if cbook .iterable (colors ):
481
+ colors = np .asarray (colors )[igood ]
482
+ if cbook .iterable (linewidths ):
483
+ linewidths = np .asarray (linewidths )[igood ]
484
+ N = len (y )
478
485
x = np .array ([0.0 , 1.0 ])
479
486
X , Y = np .meshgrid (x ,y )
480
487
if self .orientation == 'vertical' :
@@ -528,7 +535,10 @@ def _ticker(self):
528
535
locator .axis .get_minpos = lambda : intv [0 ]
529
536
formatter .axis .get_minpos = lambda : intv [0 ]
530
537
b = np .array (locator ())
531
- b , ticks = self ._locate (b )
538
+ ticks = self ._locate (b )
539
+ inrange = (ticks > - 0.001 ) & (ticks < 1.001 )
540
+ ticks = ticks [inrange ]
541
+ b = b [inrange ]
532
542
formatter .set_locs (b )
533
543
ticklabels = [formatter (t , i ) for i , t in enumerate (b )]
534
544
offset_string = formatter .get_offset ()
@@ -746,37 +756,36 @@ def _mesh(self):
746
756
747
757
def _locate (self , x ):
748
758
'''
749
- Given a possible set of color data values, return the ones
750
- within range, together with their corresponding colorbar
751
- data coordinates.
759
+ Given a set of color data values, return their
760
+ corresponding colorbar data coordinates.
752
761
'''
753
762
if isinstance (self .norm , (colors .NoNorm , colors .BoundaryNorm )):
754
763
b = self ._boundaries
755
764
xn = x
756
- xout = x
757
765
else :
758
766
# Do calculations using normalized coordinates so
759
767
# as to make the interpolation more accurate.
760
768
b = self .norm (self ._boundaries , clip = False ).filled ()
761
- # We do our own clipping so that we can allow a tiny
762
- # bit of slop in the end point ticks to allow for
763
- # floating point errors.
764
769
xn = self .norm (x , clip = False ).filled ()
765
- in_cond = (xn > - 0.001 ) & (xn < 1.001 )
766
- xn = np .compress (in_cond , xn )
767
- xout = np .compress (in_cond , x )
768
- # The rest is linear interpolation with clipping.
770
+ # The rest is linear interpolation with extrapolation at ends.
769
771
y = self ._y
770
772
N = len (b )
771
- ii = np .minimum (np .searchsorted (b , xn ), N - 1 )
772
- i0 = np .maximum (ii - 1 , 0 )
773
+ ii = np .searchsorted (b , xn )
774
+ i0 = ii - 1
775
+ itop = (ii == N )
776
+ ibot = (ii == 0 )
777
+ i0 [itop ] -= 1
778
+ ii [itop ] -= 1
779
+ i0 [ibot ] += 1
780
+ ii [ibot ] += 1
781
+
773
782
#db = b[ii] - b[i0]
774
783
db = np .take (b , ii ) - np .take (b , i0 )
775
- db = np .where (i0 == ii , 1.0 , db )
776
784
#dy = y[ii] - y[i0]
777
785
dy = np .take (y , ii ) - np .take (y , i0 )
778
786
z = np .take (y , i0 ) + (xn - np .take (b ,i0 ))* dy / db
779
- return xout , z
787
+
788
+ return z
780
789
781
790
def set_alpha (self , alpha ):
782
791
self .alpha = alpha
0 commit comments