[SciPy-user] Plotting an array

Steve Schmerler elcorto at gmx.net
Tue Oct 10 12:15:21 EDT 2006


Andrew B. Young wrote:
> I believe this is a rookie question but the I've not discovered the
> answer so easily.  The code below, copied from a posting I found,
> produces a graph with a straight line across zero.  Plotting just t,
> plot(t), produces a line either zero or one.  I am sure it has
> something to do with plotting an array versus plotting a python list.

Hmmm, t, y, tnew and ynew are <type 'numpy.ndarray'> in my case (try 
type(t) etc. to find out).
The only list is tck, but is not plotted (it contains infos about the 
spline and is passed to splev).

numpy 1.0rc1.dev3144
scipy 0.5.2.dev2197
matplotlib 0.87.5 Rev 2761

> I would be happy for a pointer to the reference material for me to
> read.  http://www.scipy.org/Documentation has not yet lead me to the
> answer.
> 
> 
>   t = arange(0, 2.0, 0.1)
>   y = sin(2*pi*t)
>   tck = interpolate.splrep(t, y, s=0)
>   tnew = arange(0, 2.0, 0.01)
>   ynew = interpolate.splev(tnew, tck, der=0)
>   plot(t, y, 'o', tnew, ynew)
>   show()
> 

PS: Rather unimportant note to the scipy guys:

In [27]: len(tck)
Out[27]: 3
In [28]: type(tck)
Out[28]: <type 'list'>

The splrep docstring says tck is a len 3 tuple, not a list ...

-- 
cheers,
steve

Random number generation is the art of producing pure gibberish as 
quickly as possible.



More information about the SciPy-User mailing list