From: Peter G. <pgr...@ge...> - 2004-04-12 20:50:25
|
John Hunter wrote: [snip] >Here is a sample implementation > >from matplotlib.matlab import * >def segplot(x, y, fmt, maxdelta, **kwargs): > """ > Plot x versus y, breaking the plot at any point where x[i] - > x[i-1] > maxdelta. kwargs are passed on to plot > """ > x = asarray(x) > y = asarray(y) > d = diff(x) > lines = [] > ind = nonzero(greater(d, maxdelta)) > ind = ind+1 > if not len(ind): > lines.extend( plot(x,y,fmt,**kwargs) ) > else: > allind = [0] > allind.extend(ind) > allind.append(len(x)) > for i1,i2 in zip(allind[:-1], allind[1:]): > lines.extend( plot(x[i1:i2], y[i1:i2], fmt, **kwargs) ) > return lines > >t = [0,1,2,3,4,5,105,106,107,187, 200, 212, 300, 320] >s = [1,4,5,3,9,11,-5,-8,3,12, 15, 12, -1, 3] >segplot(t, s, 'b-o', 40, antialiased=False) >grid(True) >show() > >I'm inclined not to make this part of plot, since plot processes a >variable number of arguments it makes it a little difficult. >Certainly doable, but I'm hesitant to put too much on plot because it >might become unwieldy. But a new function, like segment plot, would >be easy enough to include. > >Any suggestions for a name, or additional functionality? > > Thanks for the quick solution. I think the name is just fine. Best, -- Peter Groszkowski Gemini Observatory Tel: +1 808 974-2509 670 N. A'ohoku Place Fax: +1 808 935-9235 Hilo, Hawai'i 96720, USA |