From: <jd...@us...> - 2008-11-23 19:56:41
|
Revision: 6437 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6437&view=rev Author: jdh2358 Date: 2008-11-23 19:56:37 +0000 (Sun, 23 Nov 2008) Log Message: ----------- moved fill_between to axes/pyplot method Modified Paths: -------------- trunk/matplotlib/boilerplate.py trunk/matplotlib/doc/_templates/index.html trunk/matplotlib/examples/api/fill_where_demo.py trunk/matplotlib/examples/pylab_examples/fill_between.py trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/collections.py trunk/matplotlib/lib/matplotlib/pyplot.py Added Paths: ----------- trunk/matplotlib/examples/api/span_regions.py Modified: trunk/matplotlib/boilerplate.py =================================================================== --- trunk/matplotlib/boilerplate.py 2008-11-23 19:18:24 UTC (rev 6436) +++ trunk/matplotlib/boilerplate.py 2008-11-23 19:56:37 UTC (rev 6437) @@ -64,6 +64,7 @@ 'csd', 'errorbar', 'fill', + 'fill_between', 'hexbin', 'hist', 'hlines', Modified: trunk/matplotlib/doc/_templates/index.html =================================================================== --- trunk/matplotlib/doc/_templates/index.html 2008-11-23 19:18:24 UTC (rev 6436) +++ trunk/matplotlib/doc/_templates/index.html 2008-11-23 19:56:37 UTC (rev 6437) @@ -409,8 +409,21 @@ </td> </tr> + <tr> <th align="left"> + <a href="api/pyplot_api.html#matplotlib.pyplot.fill_between">fill_between</a> + + </th> + + <td align="left"> + make filled polygons between two curves + </td> + + </tr> + + <tr> + <th align="left"> <a href="api/pyplot_api.html#matplotlib.pyplot.findobj">findobj</a> </th> Modified: trunk/matplotlib/examples/api/fill_where_demo.py =================================================================== --- trunk/matplotlib/examples/api/fill_where_demo.py 2008-11-23 19:18:24 UTC (rev 6436) +++ trunk/matplotlib/examples/api/fill_where_demo.py 2008-11-23 19:56:37 UTC (rev 6437) @@ -17,7 +17,7 @@ fig = plt.figure() ax = fig.add_subplot(111) ax.set_title('using fill_between_where') -ax.plot(t, s1, t, s2) +ax.plot(t, s1, t, s2, color='black') ax.axhline(0, color='black', lw=2) collection = collections.PolyCollection.fill_between_where( @@ -32,7 +32,7 @@ fig = plt.figure() ax = fig.add_subplot(111) ax.set_title('using span_where') -ax.plot(t, s1, '-') +ax.plot(t, s1, , color='black') ax.axhline(0, color='black', lw=2) collection = collections.BrokenBarHCollection.span_where( Added: trunk/matplotlib/examples/api/span_regions.py =================================================================== --- trunk/matplotlib/examples/api/span_regions.py (rev 0) +++ trunk/matplotlib/examples/api/span_regions.py 2008-11-23 19:56:37 UTC (rev 6437) @@ -0,0 +1,38 @@ +""" +Illustrate some helper functions for shading regions where a logical +mask is True + +See :meth:`matplotlib.collections.BrokenBarHCollection.span_where` +""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.collections as collections + + +t = np.arange(0.0, 2, 0.01) +s1 = np.sin(2*np.pi*t) +s2 = 1.2*np.sin(4*np.pi*t) + + +fig = plt.figure() +ax = fig.add_subplot(111) +ax.set_title('using span_where') +ax.plot(t, s1, color='black') +ax.axhline(0, color='black', lw=2) + +collection = collections.BrokenBarHCollection.span_where( + t, ymin=0, ymax=1, where=s1>0, facecolor='green', alpha=0.5) +ax.add_collection(collection) + +collection = collections.BrokenBarHCollection.span_where( + t, ymin=-1, ymax=0, where=s1<0, facecolor='red', alpha=0.5) +ax.add_collection(collection) + + + +plt.show() + + + + + Modified: trunk/matplotlib/examples/pylab_examples/fill_between.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/fill_between.py 2008-11-23 19:18:24 UTC (rev 6436) +++ trunk/matplotlib/examples/pylab_examples/fill_between.py 2008-11-23 19:56:37 UTC (rev 6437) @@ -3,27 +3,31 @@ from pylab import figure, show import numpy as np -x = np.arange(0, 2, 0.01) +x = np.arange(0.0, 2, 0.01) y1 = np.sin(2*np.pi*x) -y2 = np.sin(4*np.pi*x) + 2 +y2 = 1.2*np.sin(4*np.pi*x) fig = figure() -ax = fig.add_subplot(311) -ax2 = fig.add_subplot(312) -ax3 = fig.add_subplot(313) +ax1 = fig.add_subplot(311) +ax2 = fig.add_subplot(312, sharex=ax1) +ax3 = fig.add_subplot(313, sharex=ax1) +ax1.fill_between(x, 0, y1) +ax1.set_ylabel('between y1 and 0') -xs, ys = mlab.poly_between(x, 0, y1) -ax.fill(xs, ys) -ax.set_ylabel('between y1 and 0') - -xs, ys = mlab.poly_between(x, y1, 1) -ax2.fill(xs, ys) +ax2.fill_between(x, y1, 1) ax2.set_ylabel('between y1 and 1') -xs, ys = mlab.poly_between(x, y1, y2) -ax3.fill(xs, ys) +ax3.fill_between(x, y1, y2) ax3.set_ylabel('between y1 and y2') ax3.set_xlabel('x') + +fig = figure() +ax = fig.add_subplot(111) +ax1.plot(x, y1, x, y2, color='black') +ax.fill_between(x, y1, y2, where=y2>y1, facecolor='green') +ax.fill_between(x, y1, y2, where=y2<=y1, facecolor='red') +ax.set_title('fill between where') + show() Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-11-23 19:18:24 UTC (rev 6436) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-11-23 19:56:37 UTC (rev 6437) @@ -1302,6 +1302,7 @@ if autolim: if collection._paths and len(collection._paths): self.update_datalim(collection.get_datalim(self.transData)) + collection._remove_method = lambda h: self.collections.remove(h) def add_line(self, line): @@ -5456,12 +5457,8 @@ supports are supported by the fill format string. If you would like to fill below a curve, eg. shade a region - between 0 and *y* along *x*, use - :func:`~matplotlib.pylab.poly_between`, eg.:: + between 0 and *y* along *x*, use :meth:`fill_between` - xs, ys = poly_between(x, 0, y) - axes.fill(xs, ys, facecolor='red', alpha=0.5) - The *closed* kwarg will close the polygon when *True* (default). kwargs control the Polygon properties: @@ -5472,9 +5469,6 @@ .. plot:: mpl_examples/pylab_examples/fill_demo.py - .. seealso:: - :file:`examples/pylab_examples/fill_between.py`: - For more examples. """ if not self._hold: self.cla() @@ -5486,6 +5480,92 @@ return patches fill.__doc__ = cbook.dedent(fill.__doc__) % martist.kwdocd + def fill_between(self, x, y1, y2=0, where=None, **kwargs): + """ + call signature:: + + fill_between(x, y1, y2=0, where=None, **kwargs) + + Create a :class:`~matplotlib.collectionsPolyCollection` + filling the regions between *y1* and *y2* where + ``where==True`` + + *x* + an N length np array of the x data + + *y1* + an N length scalar or np array of the x data + + *y2* + an N length scalar or np array of the x data + + *where* + if None, default to fill between everywhere. If not None, + it is a a N length numpy boolean array and the fill will + only happen over the regions where ``where==True`` + + *kwargs* + keyword args passed on to the :class:`PolyCollection` + + .. seealso:: + :file:`examples/pylab_examples/fill_between.py`: + For more examples. + + kwargs control the Polygon properties: + + %(PolyCollection)s + + """ + x = np.asarray(x) + if not cbook.iterable(y1): + y1 = np.ones_like(x)*y1 + + if not cbook.iterable(y2): + y2 = np.ones_like(x)*y2 + + if where is None: + where = np.ones(len(x), np.bool) + + y1 = np.asarray(y1) + y2 = np.asarray(y2) + where = np.asarray(where) + assert( (len(x)==len(y1)) and (len(x)==len(y2)) and len(x)==len(where)) + + polys = [] + for ind0, ind1 in mlab.contiguous_regions(where): + theseverts = [] + xslice = x[ind0:ind1] + y1slice = y1[ind0:ind1] + y2slice = y2[ind0:ind1] + + if not len(xslice): + continue + + N = len(xslice) + X = np.zeros((2*N+2, 2), np.float) + + # the purpose of the next two lines is for when y2 is a + # scalar like 0 and we want the fill to go all the way + # down to 0 even if none of the y1 sample points do + X[0] = xslice[0], y2slice[0] + X[N+1] = xslice[-1], y2slice[-1] + + X[1:N+1,0] = xslice + X[1:N+1,1] = y1slice + X[N+2:,0] = xslice[::-1] + X[N+2:,1] = y2slice[::-1] + + polys.append(X) + + collection = mcoll.PolyCollection(polys, **kwargs) + + self.update_datalim_numerix(x[where], y1[where]) + self.update_datalim_numerix(x[where], y2[where]) + self.add_collection(collection) + self.autoscale_view() + return collection + fill_between.__doc__ = cbook.dedent(fill_between.__doc__) % martist.kwdocd + #### plotting z(x,y): imshow, pcolor and relatives, contour def imshow(self, X, cmap=None, norm=None, aspect=None, Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2008-11-23 19:18:24 UTC (rev 6436) +++ trunk/matplotlib/lib/matplotlib/collections.py 2008-11-23 19:56:37 UTC (rev 6437) @@ -673,66 +673,6 @@ return Collection.draw(self, renderer) - @staticmethod - def fill_between_where(x, y1, y2, where, **kwargs): - """ - Create a :class:`PolyCollection` filling the regions between *y* - and *yboundary7* where ``where==True`` - - - *x* - an N length np array of the x data - - *y1* - an N length scalar or np array of the x data - - *y2* - an N length scalar or np array of the x data - - *where* - an N length numpy boolean array - - *kwargs* - keyword args passed on to the :class:`PolyCollection` - - """ - if not cbook.iterable(y1): - y1 = np.ones_like(x)*y1 - - if not cbook.iterable(y2): - y2 = np.ones_like(x)*y2 - - assert( (len(x)==len(y1)) and (len(x)==len(y2)) ) - - polys = [] - for ind0, ind1 in mlab.contiguous_regions(where): - theseverts = [] - xslice = x[ind0:ind1] - y1slice = y1[ind0:ind1] - y2slice = y2[ind0:ind1] - - if not len(xslice): - continue - - N = len(xslice) - X = np.zeros((2*N+2, 2), np.float) - - # the purpose of the next two lines is for when y2 is a - # scalar like 0 and we want the fill to go all the way - # down to 0 even if none of the y1 sample points do - X[0] = xslice[0], y2slice[0] - X[N+1] = xslice[-1], y2slice[-1] - - X[1:N+1,0] = xslice - X[1:N+1,1] = y1slice - X[N+2:,0] = xslice[::-1] - X[N+2:,1] = y2slice[::-1] - - polys.append(X) - - collection = PolyCollection(polys, **kwargs) - return collection - class BrokenBarHCollection(PolyCollection): """ A collection of horizontal bars spanning *yrange* with a sequence of Modified: trunk/matplotlib/lib/matplotlib/pyplot.py =================================================================== --- trunk/matplotlib/lib/matplotlib/pyplot.py 2008-11-23 19:18:24 UTC (rev 6436) +++ trunk/matplotlib/lib/matplotlib/pyplot.py 2008-11-23 19:56:37 UTC (rev 6437) @@ -1120,61 +1120,62 @@ """ Plotting commands - ========= ================================================= - Command Description - ========= ================================================= - axes Create a new axes - axis Set or return the current axis limits - bar make a bar chart - boxplot make a box and whiskers chart - cla clear current axes - clabel label a contour plot - clf clear a figure window - close close a figure window - colorbar add a colorbar to the current figure - cohere make a plot of coherence - contour make a contour plot - contourf make a filled contour plot - csd make a plot of cross spectral density - draw force a redraw of the current figure - errorbar make an errorbar graph - figlegend add a legend to the figure - figimage add an image to the figure, w/o resampling - figtext add text in figure coords - figure create or change active figure - fill make filled polygons - gca return the current axes - gcf return the current figure - gci get the current image, or None - getp get a handle graphics property - hist make a histogram - hold set the hold state on current axes - legend add a legend to the axes - loglog a log log plot - imread load image file into array - imshow plot image data - matshow display a matrix in a new figure preserving aspect - pcolor make a pseudocolor plot - plot make a line plot - plotfile plot data from a flat file - psd make a plot of power spectral density - quiver make a direction field (arrows) plot - rc control the default params - savefig save the current figure - scatter make a scatter plot - setp set a handle graphics property - semilogx log x axis - semilogy log y axis - show show the figures - specgram a spectrogram plot - stem make a stem plot - subplot make a subplot (numrows, numcols, axesnum) - table add a table to the axes - text add some text at location x,y to the current axes - title add a title to the current axes - xlabel add an xlabel to the current axes - ylabel add a ylabel to the current axes - ========= ================================================= + ========= ================================================= + Command Description + ========= ================================================= + axes Create a new axes + axis Set or return the current axis limits + bar make a bar chart + boxplot make a box and whiskers chart + cla clear current axes + clabel label a contour plot + clf clear a figure window + close close a figure window + colorbar add a colorbar to the current figure + cohere make a plot of coherence + contour make a contour plot + contourf make a filled contour plot + csd make a plot of cross spectral density + draw force a redraw of the current figure + errorbar make an errorbar graph + figlegend add a legend to the figure + figimage add an image to the figure, w/o resampling + figtext add text in figure coords + figure create or change active figure + fill make filled polygons + fill_between make filled polygons + gca return the current axes + gcf return the current figure + gci get the current image, or None + getp get a handle graphics property + hist make a histogram + hold set the hold state on current axes + legend add a legend to the axes + loglog a log log plot + imread load image file into array + imshow plot image data + matshow display a matrix in a new figure preserving aspect + pcolor make a pseudocolor plot + plot make a line plot + plotfile plot data from a flat file + psd make a plot of power spectral density + quiver make a direction field (arrows) plot + rc control the default params + savefig save the current figure + scatter make a scatter plot + setp set a handle graphics property + semilogx log x axis + semilogy log y axis + show show the figures + specgram a spectrogram plot + stem make a stem plot + subplot make a subplot (numrows, numcols, axesnum) + table add a table to the axes + text add some text at location x,y to the current axes + title add a title to the current axes + xlabel add an xlabel to the current axes + ylabel add a ylabel to the current axes + ========= ================================================= The following commands will set the default colormap accordingly: @@ -1493,7 +1494,6 @@ ## Plotting part 2: autogenerated wrappers for axes methods ## -### Do not edit below this point # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost def acorr(*args, **kwargs): @@ -1870,6 +1870,50 @@ # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost +def fill_between(*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().fill_between(*args, **kwargs) + draw_if_interactive() + except: + hold(b) + raise + + hold(b) + return ret +if Axes.fill_between.__doc__ is not None: + fill_between.__doc__ = dedent(Axes.fill_between.__doc__) + """ + +Additional kwargs: hold = [True|False] overrides default hold state""" + +# This function was autogenerated by boilerplate.py. Do not edit as +# changes will be lost +def hexbin(*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().hexbin(*args, **kwargs) + draw_if_interactive() + except: + hold(b) + raise + gci._current = ret + hold(b) + return ret +if Axes.hexbin.__doc__ is not None: + hexbin.__doc__ = dedent(Axes.hexbin.__doc__) + """ + +Additional kwargs: hold = [True|False] overrides default hold state""" + +# This function was autogenerated by boilerplate.py. Do not edit as +# changes will be lost def hist(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() @@ -2156,28 +2200,6 @@ # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost -def hexbin(*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().hexbin(*args, **kwargs) - draw_if_interactive() - except: - hold(b) - raise - gci._current = ret - hold(b) - return ret -if Axes.hexbin.__doc__ is not None: - hexbin.__doc__ = dedent(Axes.hexbin.__doc__) + """ - -Additional kwargs: hold = [True|False] overrides default hold state""" - -# This function was autogenerated by boilerplate.py. Do not edit as -# changes will be lost def semilogx(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() @@ -2438,10 +2460,8 @@ # changes will be lost def autumn(): ''' - Set the default colormap to *autumn* and apply to current image if any. - - .. seealso:: - :func:`colormaps` + set the default colormap to autumn and apply to current image if any. + See help(colormaps) for more information ''' rc('image', cmap='autumn') im = gci() @@ -2455,10 +2475,8 @@ # changes will be lost def bone(): ''' - Set the default colormap to bone and apply to current image if any. - - .. seealso:: - :func:`colormaps` + set the default colormap to bone and apply to current image if any. + See help(colormaps) for more information ''' rc('image', cmap='bone') im = gci() @@ -2472,10 +2490,8 @@ # changes will be lost def cool(): ''' - Set the default colormap to cool and apply to current image if any. - - .. seealso:: - :func:`colormaps` + set the default colormap to cool and apply to current image if any. + See help(colormaps) for more information ''' rc('image', cmap='cool') im = gci() @@ -2489,10 +2505,8 @@ # changes will be lost def copper(): ''' - Set the default colormap to copper and apply to current image if any. - - .. seealso:: - :func:`colormaps` + set the default colormap to copper and apply to current image if any. + See help(colormaps) for more information ''' rc('image', cmap='copper') im = gci() @@ -2506,10 +2520,8 @@ # changes will be lost def flag(): ''' - Set the default colormap to flag and apply to current image if any. - - .. seealso:: - :func:`colormaps` + set the default colormap to flag and apply to current image if any. + See help(colormaps) for more information ''' rc('image', cmap='flag') im = gci() @@ -2523,10 +2535,8 @@ # changes will be lost def gray(): ''' - Set the default colormap to gray and apply to current image if any. - - .. seealso:: - :func:`colormaps` + set the default colormap to gray and apply to current image if any. + See help(colormaps) for more information ''' rc('image', cmap='gray') im = gci() @@ -2540,10 +2550,8 @@ # changes will be lost def hot(): ''' - Set the default colormap to hot and apply to current image if any. - - .. seealso:: - :func:`colormaps` + set the default colormap to hot and apply to current image if any. + See help(colormaps) for more information ''' rc('image', cmap='hot') im = gci() @@ -2557,10 +2565,8 @@ # changes will be lost def hsv(): ''' - Set the default colormap to hsv and apply to current image if any. - - .. seealso:: - :func:`colormaps` + set the default colormap to hsv and apply to current image if any. + See help(colormaps) for more information ''' rc('image', cmap='hsv') im = gci() @@ -2574,10 +2580,8 @@ # changes will be lost def jet(): ''' - Set the default colormap to jet and apply to current image if any. - - .. seealso:: - :func:`colormaps` + set the default colormap to jet and apply to current image if any. + See help(colormaps) for more information ''' rc('image', cmap='jet') im = gci() @@ -2591,10 +2595,8 @@ # changes will be lost def pink(): ''' - Set the default colormap to pink and apply to current image if any. - - .. seealso:: - :func:`colormaps` + set the default colormap to pink and apply to current image if any. + See help(colormaps) for more information ''' rc('image', cmap='pink') im = gci() @@ -2608,10 +2610,8 @@ # changes will be lost def prism(): ''' - Set the default colormap to prism and apply to current image if any. - - .. seealso:: - :func:`colormaps` + set the default colormap to prism and apply to current image if any. + See help(colormaps) for more information ''' rc('image', cmap='prism') im = gci() @@ -2625,10 +2625,8 @@ # changes will be lost def spring(): ''' - Set the default colormap to spring and apply to current image if any. - - .. seealso:: - :func:`colormaps` + set the default colormap to spring and apply to current image if any. + See help(colormaps) for more information ''' rc('image', cmap='spring') im = gci() @@ -2642,10 +2640,8 @@ # changes will be lost def summer(): ''' - Set the default colormap to summer and apply to current image if any. - - .. seealso:: - :func:`colormaps` + set the default colormap to summer and apply to current image if any. + See help(colormaps) for more information ''' rc('image', cmap='summer') im = gci() @@ -2659,10 +2655,8 @@ # changes will be lost def winter(): ''' - Set the default colormap to winter and apply to current image if any. - - .. seealso:: - :func:`colormaps` + set the default colormap to winter and apply to current image if any. + See help(colormaps) for more information ''' rc('image', cmap='winter') im = gci() @@ -2676,10 +2670,8 @@ # changes will be lost def spectral(): ''' - Set the default colormap to spectral and apply to current image if any. - - .. seealso:: - :func:`colormaps` + set the default colormap to spectral and apply to current image if any. + See help(colormaps) for more information ''' rc('image', cmap='spectral') im = gci() @@ -2687,3 +2679,5 @@ if im is not None: im.set_cmap(cm.spectral) draw_if_interactive() + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |