99import sys
1010
1111from numerix import Float , alltrue , arange , array , logical_and ,\
12- nonzero , searchsorted , take , asarray , ones , where , less , ravel
12+ nonzero , searchsorted , take , asarray , ones , where , less , ravel , \
13+ greater , logical_and
1314from matplotlib import verbose
1415from artist import Artist
1516from cbook import iterable , is_string_like
1617from collections import RegularPolyCollection , PolyCollection
1718from colors import colorConverter
1819from patches import bbox_artist
19- from transforms import lbwh_to_bbox
20+ from transforms import lbwh_to_bbox , LOG10
2021from matplotlib import rcParams
2122
2223TICKLEFT , TICKRIGHT , TICKUP , TICKDOWN = range (4 )
@@ -140,6 +141,7 @@ def __init__(self, xdata, ydata,
140141 self ._lineFunc = self ._lineStyles .get (linestyle , self ._draw_nothing )
141142 self ._markerFunc = self ._markers .get (marker , self ._draw_nothing )
142143
144+ self ._logcache = None
143145
144146 def get_window_extent (self , renderer ):
145147 x , y = self ._get_numeric_clipped_data_in_range ()
@@ -193,6 +195,8 @@ def set_data(self, *args):
193195 raise RuntimeError ('xdata and ydata must be the same length' )
194196
195197 if self ._useDataClipping : self ._xsorted = self ._is_sorted (self ._x )
198+
199+ self ._logcache = None
196200
197201 def set_data_clipping (self , b ):
198202 """
@@ -210,12 +214,37 @@ def _is_sorted(self, x):
210214
211215 def _get_numeric_clipped_data_in_range (self ):
212216 # if the x or y clip is set, only plot the points in the
213- # clipping region
217+ # clipping region. If log scale is set, only pos data will be
218+ # returned
214219 try : self ._xc , self ._yc
215220 except AttributeError : x , y = self ._x , self ._y
216221 else : x , y = self ._xc , self ._yc
217222
218-
223+ try : logx = self ._transform .get_funcx ().get_type ()== LOG10
224+ except RuntimeError : logx = False # non-separable
225+
226+ try : logy = self ._transform .get_funcy ().get_type ()== LOG10
227+ except RuntimeError : logy = False # non-separable
228+
229+ if not logx and not logy : return x , y
230+
231+ if self ._logcache is not None :
232+ return self ._logcache
233+
234+ Nx = len (x )
235+ Ny = len (y )
236+
237+ if logx : indx = greater (x , 0 )
238+ else : indx = ones (len (x ))
239+
240+ if logy : indy = greater (y , 0 )
241+ else : indy = ones (len (y ))
242+
243+ ind = nonzero (logical_and (indx , indy ))
244+ x = take (x , ind )
245+ y = take (y , ind )
246+
247+ self ._logcache = x , y
219248 return x , y
220249
221250 def draw (self , renderer ):
@@ -267,8 +296,11 @@ def get_ydata(self): return self._y
267296
268297
269298 def _set_clip (self ):
299+
270300
271301 if not self ._useDataClipping : return
302+ #self._logcache = None
303+
272304 try : self ._xmin , self ._xmax
273305 except AttributeError : indx = arange (len (self ._x ))
274306 else :
@@ -402,7 +434,7 @@ def set_xdata(self, x):
402434 except AttributeError : pass
403435
404436 self .set_data (x , self ._y )
405-
437+
406438 def set_ydata (self , y ):
407439 """
408440Set the data array for y
@@ -427,6 +459,8 @@ def set_xclip(self, *args):
427459 self ._xmin , self ._xmax = xmin , xmax
428460 self ._set_clip ()
429461
462+
463+
430464 def set_yclip (self , * args ):
431465 """
432466Set the y clipping range for data clipping to ymin, ymax
0 commit comments