From: <ef...@us...> - 2009-04-29 19:38:47
|
Revision: 7071 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7071&view=rev Author: efiring Date: 2009-04-29 19:38:35 +0000 (Wed, 29 Apr 2009) Log Message: ----------- Condense argument handling in fill_between, and add masked example Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/fill_between.py trunk/matplotlib/lib/matplotlib/axes.py Modified: trunk/matplotlib/examples/pylab_examples/fill_between.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/fill_between.py 2009-04-29 16:07:27 UTC (rev 7070) +++ trunk/matplotlib/examples/pylab_examples/fill_between.py 2009-04-29 19:38:35 UTC (rev 7071) @@ -1,6 +1,6 @@ #!/usr/bin/env python import matplotlib.mlab as mlab -from pylab import figure, show +from matplotlib.pyplot import figure, show import numpy as np x = np.arange(0.0, 2, 0.01) @@ -27,11 +27,24 @@ # fill_between(x[where], y1[where],y2[where] # because of edge effects over multiple contiguous regions. fig = figure() -ax = fig.add_subplot(111) +ax = fig.add_subplot(211) ax.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='green') ax.fill_between(x, y1, y2, where=y2<=y1, facecolor='red') ax.set_title('fill between where') +# Test support for masked arrays. +y2 = np.ma.masked_greater(y2, 1.0) +ax1 = fig.add_subplot(212, sharex=ax) +ax1.plot(x, y1, x, y2, color='black') +ax1.fill_between(x, y1, y2, where=y2>=y1, facecolor='green') +ax1.fill_between(x, y1, y2, where=y2<=y1, facecolor='red') +ax1.set_title('Now regions with y2>1 are masked') + +# This example illustrates a problem; because of the data +# gridding, there are undesired unfilled triangles at the crossover +# points. A brute-force solution would be to interpolate all +# arrays to a very fine grid before plotting. + show() Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2009-04-29 16:07:27 UTC (rev 7070) +++ trunk/matplotlib/lib/matplotlib/axes.py 2009-04-29 19:38:35 UTC (rev 7071) @@ -5832,40 +5832,29 @@ self._process_unit_info(xdata=x, ydata=y1, kwargs=kwargs) self._process_unit_info(ydata=y2) - if where is None: - where = np.ones(len(x), np.bool) - else: - where = np.asarray(where) - - maskedx = isinstance(x, np.ma.MaskedArray) - maskedy1 = isinstance(y1, np.ma.MaskedArray) - maskedy2 = isinstance(y2, np.ma.MaskedArray) - - if (maskedx or maskedy1 or maskedy2): - if maskedx: - where = where & (~x.mask) - - if maskedy1: - where = where & (~y1.mask) - - if maskedy2: - where = where & (~y2.mask) - - # Convert the arrays so we can work with them - x = np.asarray(self.convert_xunits(x)) - y1 = np.asarray(self.convert_yunits(y1)) - y2 = np.asarray(self.convert_yunits(y2)) + x = np.asanyarray(self.convert_xunits(x)) + y1 = np.asanyarray(self.convert_yunits(y1)) + y2 = np.asanyarray(self.convert_yunits(y2)) - if not cbook.iterable(y1): + if y1.ndim == 0: y1 = np.ones_like(x)*y1 - - if not cbook.iterable(y2): + if y2.ndim == 0: y2 = np.ones_like(x)*y2 + if where is None: + where = np.ones(len(x), np.bool) + else: + where = np.asarray(where, np.bool) - assert( (len(x)==len(y1)) and (len(x)==len(y2)) and len(x)==len(where)) + if not (x.shape == y1.shape == y2.shape == where.shape): + raise ValueError("Argument dimensions are incompatible") + mask = reduce(ma.mask_or, + [ma.getmask(x), ma.getmask(y1), ma.getmask(y2)]) + if mask is not ma.nomask: + where &= ~mask + polys = [] for ind0, ind1 in mlab.contiguous_regions(where): theseverts = [] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |