From: <jd...@us...> - 2009-06-05 16:49:32
|
Revision: 7179 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7179&view=rev Author: jdh2358 Date: 2009-06-05 16:49:29 +0000 (Fri, 05 Jun 2009) Log Message: ----------- added example to fill_between to show how to create multiple axes spans where a condition is true Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/fill_between.py Modified: trunk/matplotlib/examples/pylab_examples/fill_between.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/fill_between.py 2009-06-05 13:00:47 UTC (rev 7178) +++ trunk/matplotlib/examples/pylab_examples/fill_between.py 2009-06-05 16:49:29 UTC (rev 7179) @@ -46,5 +46,21 @@ # points. A brute-force solution would be to interpolate all # arrays to a very fine grid before plotting. +# show how to use transforms to create axes spans where a certain condition is satisfied +fig = figure() +ax = fig.add_subplot(111) +y = np.sin(4*np.pi*x) +ax.plot(x, y, color='black') + +# use the data coordinates for the x-axis and the axes coordinates for the y-axis +import matplotlib.transforms as mtransforms +trans = mtransforms.blended_transform_factory(ax.transData, ax.transAxes) +ax.axhline(0.5, color='green', lw=2, alpha=0.5) +ax.axhline(-0.5, color='red', lw=2, alpha=0.5) +ax.fill_between(x, 0, 1, where=y2>0.5, facecolor='green', alpha=0.5, transform=trans) +ax.fill_between(x, 0, 1, where=y2<-0.5, facecolor='red', alpha=0.5, transform=trans) + + + show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |