5757from __future__ import division
5858import sys , random , datetime , csv
5959
60+ import numpy as npy
6061
6162from matplotlib import verbose
6263import numpy as npy
7778from numerix .mlab import hanning , cov , diff , svd , rand , std
7879from numerix .fft import fft , inverse_fft
7980
80- from cbook import iterable , is_string_like , to_filehandle
81+ from cbook import iterable , is_string_like , to_filehandle , reversed
8182
8283try : set
8384except NameError :
@@ -1680,6 +1681,7 @@ def angle(x1, y1, x2, y2):
16801681 angles += a
16811682 return nx .nonzero (nx .greater_equal (nx .absolute (angles ), nx .pi ))
16821683
1684+
16831685def inside_poly (points , verts ):
16841686 """
16851687 points is a sequence of x,y points
@@ -1690,6 +1692,48 @@ def inside_poly(points, verts):
16901692 """
16911693 return nx .nonzero (nxutils .points_inside_poly (points , verts ))
16921694
1695+ def poly_below (xmin , xs , ys ):
1696+ """
1697+ given a sequence of xs and ys, return the vertices of a polygon
1698+ that has a horzontal base at xmin and an upper bound at the ys.
1699+ xmin is a scalar.
1700+
1701+ intended for use with Axes.fill, eg
1702+ xv, yv = poly_below(0, x, y)
1703+ ax.fill(xv, yv)
1704+ """
1705+ xs = npy .asarray (xs )
1706+ ys = npy .asarray (ys )
1707+ Nx = len (xs )
1708+ Ny = len (ys )
1709+ assert (Nx == Ny )
1710+ x = xmin * npy .ones (2 * Nx )
1711+ y = npy .ones (2 * Nx )
1712+ x [:Nx ] = xs
1713+ y [:Nx ] = ys
1714+ y [Nx :] = ys [::- 1 ]
1715+ return x , y
1716+
1717+
1718+ def poly_between (x , ylower , yupper ):
1719+ """
1720+ given a sequence of x, ylower and yupper, return the polygon that
1721+ fills the regions between them. ylower or yupper can be scalar or
1722+ iterable. If they are iterable, they must be equal in length to x
1723+
1724+ return value is x, y arrays for use with Axes.fill
1725+ """
1726+ Nx = len (x )
1727+ if not iterable (ylower ):
1728+ ylower = ylower * npy .ones (Nx )
1729+
1730+ if not iterable (yupper ):
1731+ yupper = yupper * npy .ones (Nx )
1732+
1733+ x = npy .concatenate ( (x , x [::- 1 ]) )
1734+ y = npy .concatenate ( (yupper , ylower [::- 1 ]) )
1735+ return x ,y
1736+
16931737### the following code was written and submitted by Fernando Perez
16941738### from the ipython numutils package under a BSD license
16951739# begin fperez functions
0 commit comments