> 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
Thank you very much for your answer Michael.But when I was reading your
answer, I realised that I missed to add plot items title to the elements of
datalar. So I want to change title of each curve due to index value of the
loop, how can I do that? What I mean is,
datalar = []
for ii in range(n):
Gnuplot.Data(x, ozfonksiyon(omegalar[ii],x), title=' ii . ozdeger',
with_='lines')
Best regards,
Cuneyt.
|