|
From: Michael H. <mh...@al...> - 2010-10-10 04:46:17
|
On 10/09/2010 11:30 PM, Cuneyt Ertal wrote:
> Hi,
>
> I wan to plot more than one curve in the same graph using same function
> with different parameters. The following code works without problem.
>
> from numpy import *
> import Gnuplot
>
> gp = Gnuplot.Gnuplot(persist=1)
> x = arange(0,1,0.01,dtype='float_')
> d1 = Gnuplot.Data(x, ozfonksiyon(omegalar[0],x), title='1. ozdeger',
> with_='lines')
> d2 = Gnuplot.Data(x, ozfonksiyon(omegalar[1],x), title='2. ozdeger',
> with_='lines')
> d3 = Gnuplot.Data(x, ozfonksiyon(omegalar[2],x), title='3. ozdeger',
> with_='lines')
> d4 = Gnuplot.Data(x, ozfonksiyon(omegalar[3],x), title='4. ozdeger',
> with_='lines')
> d5 = Gnuplot.Data(x, ozfonksiyon(omegalar[4],x), title='5. ozdeger',
> with_='lines')
> gp.plot(d1,d2,d3,d4,d5)
>
> in this code ozfonksiyon and omegalar are user defined functions. But
> what I want is to create plotitems (d1,d2,d3,d4,d5) in a for loop. I
> modified the code like below,
>
> for ii in range(n):
> datalar.append("Gnuplot.Data(x,
> ozfonksiyon(omegalar["+str(ii)+"],x), with_='lines')")
> gp.plot(*datalar)
>
> I get this error.
>
> /usr/bin/python -u
> "/media/disk/doktora_tezi/tek_cubuk/python_files/CALISAN
> KOD/fix_free_controlled_parametrelerin_degisimi_deneme.py"
>
> gnuplot> plot Gnuplot.Data(x, ozfonksiyon(omegalar[0],x), with_='lines')
> , Gnuplot.Data(x, ozfonksiyon(omegalar[1],x), with_='lines') ,
> Gnuplot.Data(x, ozfonksiyon(omegalar[2],x), with_='lines') ,
> Gnuplot.Data(x, ozfonksiyon(omegalar[3],x), with_='lines') ,
> Gnuplot.Data(x, ozfonksiyon(omegalar[4],x), with_='lines')
> ^
> line 0: ':' expected
>
> What am I doing wrong?
You shouldn't make the elements of the datalar array into strings; leave
them as Python objects:
datalar = []
for ii in range(n):
datalar.append(
Gnuplot.Data(x, ozfonksiyon(omegalar[ii],x), with_='lines')
)
gp.plot(*datalar)
Michael
--
Michael Haggerty
mh...@al...
http://softwareswirl.blogspot.com/
|