From: Felix U. <fel...@ui...> - 2010-04-21 11:59:44
|
Hi there, i have following problem: i want to plot a number of lines. The number of lines can be set by an user option, so i don't know it in advance. I thought of using a list of Data PlotItems. Establishing the PlotItem list works, however sending it to g.plot fails. Any idea how to do this/ work around it. Here's a testcode to illustrate what i mean: 1 import Gnuplot 2 from numpy import * 3 4 g = Gnuplot.Gnuplot(persist=1) 5 g('set terminal x11 size 1000,680') 6 7 y = [] 8 y.append([1,2,3,4,5,6]) 9 y.append([1.1,2.1,3.1,4.1,5.1,6.1]) 10 11 ga =[] 12 ga.append(Gnuplot.Data(y[0],binary=0,with_='lines')) 13 ga.append(Gnuplot.Data(y[1],binary=0,with_='lines')) 14 15 16 # --- This of course works--- 17 #g.plot(ga[0],ga[1]) 18 19 # --- This is what i want to work :-) --- 20 g.plot(ga) Looking forward to your answers! regards, Felix |
From: Cuneyt E. <cun...@gm...> - 2010-10-09 21:31:10
|
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? Best regards, Cuneyt. |
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/ |
From: Michael H. <mh...@al...> - 2010-04-21 12:43:52
|
Felix Uni wrote: > i have following problem: > i want to plot a number of lines. The number of lines can be set by an > user option, so i don't know it in advance. I thought of using a list of > Data PlotItems. Establishing the PlotItem list works, however sending it > to g.plot fails. Any idea how to do this/ work around it. > [...] > 19 # --- This is what i want to work :-) --- > 20 g.plot(ga) Use g.plot(*ga) to treat the entries in the "ga" list as individual arguments to the plot() method. Michael |
From: Felix U. <fel...@ui...> - 2010-04-21 12:44:42
|
AWESOME!!!!!!! Thanks Michael for your quick reply!! gnuplot-py rules! Felix Michael Haggerty wrote: > Felix Uni wrote: >> i have following problem: >> i want to plot a number of lines. The number of lines can be set by an >> user option, so i don't know it in advance. I thought of using a list of >> Data PlotItems. Establishing the PlotItem list works, however sending it >> to g.plot fails. Any idea how to do this/ work around it. >> [...] >> 19 # --- This is what i want to work :-) --- >> 20 g.plot(ga) > > Use > > g.plot(*ga) > > to treat the entries in the "ga" list as individual arguments to the > plot() method. > > Michael |