Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > media > contrib-backports > by-pkgid > a44f8c7e78ee9c5838c1fb080c9e7630 > files > 1260

python-matplotlib-doc-1.1.1-1mdv2010.1.noarch.rpm

.. _pylab_examples-color_by_yvalue:

pylab_examples example code: color_by_yvalue.py
===============================================



.. plot:: /home/mandrake/rpm/BUILD/matplotlib-1.1.1/doc/mpl_examples/pylab_examples/color_by_yvalue.py

::

    # use masked arrays to plot a line with different colors by y-value
    from numpy import logical_or, arange, sin, pi
    from numpy import ma
    from matplotlib.pyplot import  plot, show
    
    t = arange(0.0, 2.0, 0.01)
    s = sin(2*pi*t)
    
    upper = 0.77
    lower = -0.77
    
    
    supper = ma.masked_where(s < upper, s)
    slower = ma.masked_where(s > lower, s)
    smiddle = ma.masked_where(logical_or(s<lower, s>upper), s)
    
    plot(t, slower, 'r', t, smiddle, 'b', t, supper, 'g')
    show()
    

Keywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)