From: <ef...@us...> - 2007-08-27 14:37:30
|
Revision: 3737 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3737&view=rev Author: efiring Date: 2007-08-25 23:56:07 -0700 (Sat, 25 Aug 2007) Log Message: ----------- Added step plot based on patch by Manuel Metz Modified Paths: -------------- trunk/matplotlib/boilerplate.py trunk/matplotlib/examples/masked_demo.py trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/pylab.py Added Paths: ----------- trunk/matplotlib/examples/step_demo.py Modified: trunk/matplotlib/boilerplate.py =================================================================== --- trunk/matplotlib/boilerplate.py 2007-08-24 18:17:51 UTC (rev 3736) +++ trunk/matplotlib/boilerplate.py 2007-08-26 06:56:07 UTC (rev 3737) @@ -80,6 +80,7 @@ 'specgram', 'spy', 'stem', + 'step', 'vlines', 'quiver', 'quiverkey', Modified: trunk/matplotlib/examples/masked_demo.py =================================================================== --- trunk/matplotlib/examples/masked_demo.py 2007-08-24 18:17:51 UTC (rev 3736) +++ trunk/matplotlib/examples/masked_demo.py 2007-08-26 06:56:07 UTC (rev 3737) @@ -6,15 +6,15 @@ break the line at the data gaps. ''' -import matplotlib.numerix.ma as M +import matplotlib.numerix.npyma as ma from pylab import * -x = M.arange(0, 2*pi, 0.02) -y = M.sin(x) +x = ma.arange(0, 2*pi, 0.02) +y = ma.sin(x) y1 = sin(2*x) y2 = sin(3*x) -ym1 = M.masked_where(y1 > 0.5, y1) -ym2 = M.masked_where(y2 < -0.5, y2) +ym1 = ma.masked_where(y1 > 0.5, y1) +ym2 = ma.masked_where(y2 < -0.5, y2) lines = plot(x, y, 'r', x, ym1, 'g', x, ym2, 'bo') setp(lines[0], linewidth = 4) Added: trunk/matplotlib/examples/step_demo.py =================================================================== --- trunk/matplotlib/examples/step_demo.py (rev 0) +++ trunk/matplotlib/examples/step_demo.py 2007-08-26 06:56:07 UTC (rev 3737) @@ -0,0 +1,24 @@ +import numpy as npy +from pylab import * + +x = npy.arange(1, 7, 0.4) +y0 = npy.sin(x) +y = y0.copy() + 2.5 + +step(x, y, label='pre (default)') + +y -= 0.5 +step(x, y, where='mid', label='mid') + +y -= 0.5 +step(x, y, where='post', label='post') + +y = npy.ma.masked_where((y0>-0.15)&(y0<0.15), y - 0.5) +step(x,y, label='masked (pre)') + +legend() + +xlim(0, 7) +ylim(-0.5, 4) + +show() Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2007-08-24 18:17:51 UTC (rev 3736) +++ trunk/matplotlib/lib/matplotlib/axes.py 2007-08-26 06:56:07 UTC (rev 3737) @@ -2964,7 +2964,59 @@ #### Specialized plotting + def step(self, x, y, *args, **kwargs): + ''' + step(x, y, *args, **kwargs) + x and y must be 1-D sequences, and it is assumed, but not checked, + that x is uniformly increasing. + + Make a step plot. The args and keyword args to step are the same + as the args to plot. See help plot for more info. + + Additional keyword args for step: + + * where: can be 'pre', 'post' or 'mid'; if 'pre', the + interval from x[i] to x[i+1] has level y[i]; + if 'post', that interval has level y[i+1]; + and if 'mid', the jumps in y occur half-way + between the x-values. Default is 'pre'. + ''' + + where = kwargs.pop('where', 'pre') + + if not cbook.iterable(x): + x = ma.array([x], dtype=npy.float_) + if not cbook.iterable(y): + y = ma.array([y], dtype=npy.float_) + + if where=='pre': + x2 = ma.zeros((2*len(x)-1,), npy.float_) + y2 = ma.zeros((2*len(y)-1,), npy.float_) + + x2[0::2], x2[1::2] = x, x[:-1] + y2[0::2], y2[1:-1:2] = y, y[1:] + + elif where=='post': + x2 = ma.zeros((2*len(x)-1,), npy.float_) + y2 = ma.zeros((2*len(y)-1,), npy.float_) + + x2[::2], x2[1:-1:2] = x, x[1:] + y2[0::2], y2[1::2] = y, y[:-1] + + elif where=='mid': + x2 = ma.zeros((2*len(x),), npy.float_) + y2 = ma.zeros((2*len(y),), npy.float_) + + x2[1:-1:2] = 0.5*(x[:-1]+x[1:]) + x2[2::2] = 0.5*(x[:-1]+x[1:]) + x2[0], x2[-1] = x[0], x[-1] + + y2[0::2], y2[1::2] = y, y + + return self.plot(x2, y2, *args, **kwargs) + + def bar(self, left, height, width=0.8, bottom=None, color=None, edgecolor=None, linewidth=None, yerr=None, xerr=None, ecolor=None, capsize=3, Modified: trunk/matplotlib/lib/matplotlib/pylab.py =================================================================== --- trunk/matplotlib/lib/matplotlib/pylab.py 2007-08-24 18:17:51 UTC (rev 3736) +++ trunk/matplotlib/lib/matplotlib/pylab.py 2007-08-26 06:56:07 UTC (rev 3737) @@ -1555,7 +1555,7 @@ def acorr(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1576,7 +1576,7 @@ def arrow(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1597,7 +1597,7 @@ def axhline(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1618,7 +1618,7 @@ def axhspan(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1639,7 +1639,7 @@ def axvline(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1660,7 +1660,7 @@ def axvspan(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1681,7 +1681,7 @@ def bar(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1702,7 +1702,7 @@ def barh(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1723,7 +1723,7 @@ def broken_barh(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1744,7 +1744,7 @@ def boxplot(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1765,7 +1765,7 @@ def cohere(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1786,7 +1786,7 @@ def clabel(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1807,7 +1807,7 @@ def contour(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1828,7 +1828,7 @@ def contourf(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1849,7 +1849,7 @@ def csd(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1870,7 +1870,7 @@ def errorbar(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1891,7 +1891,7 @@ def fill(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1912,7 +1912,7 @@ def hist(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1933,7 +1933,7 @@ def hlines(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1954,7 +1954,7 @@ def imshow(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1975,7 +1975,7 @@ def loglog(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -1996,7 +1996,7 @@ def pcolor(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2017,7 +2017,7 @@ def pcolormesh(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2038,7 +2038,7 @@ def pie(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2059,7 +2059,7 @@ def plot(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2080,7 +2080,7 @@ def plot_date(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2101,7 +2101,7 @@ def psd(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2122,7 +2122,7 @@ def scatter(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2143,7 +2143,7 @@ def semilogx(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2164,7 +2164,7 @@ def semilogy(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2185,7 +2185,7 @@ def specgram(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2206,7 +2206,7 @@ def spy(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2227,7 +2227,7 @@ def stem(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2245,10 +2245,31 @@ # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost +def step(*args, **kwargs): + # allow callers to override the hold state by passing hold=True|False + b = ishold() + h = kwargs.pop('hold', None) + if h is not None: + hold(h) + try: + ret = gca().step(*args, **kwargs) + draw_if_interactive() + except: + hold(b) + raise + + hold(b) + return ret +if Axes.step.__doc__ is not None: + step.__doc__ = dedent(Axes.step.__doc__) + """ +Addition kwargs: hold = [True|False] overrides default hold state""" + +# This function was autogenerated by boilerplate.py. Do not edit as +# changes will be lost def vlines(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2269,7 +2290,7 @@ def quiver(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2290,7 +2311,7 @@ def quiverkey(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2311,7 +2332,7 @@ def xcorr(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() - h = popd(kwargs, 'hold', None) + h = kwargs.pop('hold', None) if h is not None: hold(h) try: @@ -2582,3 +2603,4 @@ draw_if_interactive() + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |