From: Nate G. <gel...@tr...> - 2003-11-06 22:53:06
|
Hi, I have a database query that returns a variable length list of hosts for which I want to plot some data about. How can I pass Gnuplot.plot a list of Gnuplot.Data types? In the past I knew how may lines I had on the graph so I could just pass g.plot(gd1,gd2,gd3,gd4) .... how do I=20 make a variable length variable list? I was trying this but got a TypeError: bad argument type for built-in operation plot_list =3D [] for i in res.keys(): print i x =3D Numeric.arange(len(res[i]),typecode=3DNumeric.Float) y =3D Numeric.zeros(len(res[i])) for j in range(0,len(res[i])): line =3D res[i] y[j] =3D line[j][0] gd =3D Gnuplot.Data(x,y,title=3Di,smooth=3Dsmoothtype) plot_list.append(gd) g.plot(plot_list) Thanks, --( Nate Gelbard, QA Engineer =20 --( Tripwire, Inc., The Integrity Assurance Company |
From: Leonardo M. <lm...@ud...> - 2003-11-06 23:36:12
|
Hi Nate > I have a database query that returns a variable length list of hosts for > which I want to plot some data about. > How can I pass Gnuplot.plot a list of Gnuplot.Data types? I don't think there is a way. Is that right Michael ? I did hack Gnuplot to do what you want. Michael, could you please take a look ? Is it safe to apply to CVS ? It seems to work for me. Replace the "_add_to_queue' method in _Gnuplot.py, by the following hacked version: #### CODE BEGINS def _add_to_queue(self, items): """Add a list of items to the itemlist (but don't plot them). 'items' is a sequence of items, each of which should be a 'PlotItem' of some kind, a string (interpreted as a function string for gnuplot to evaluate), or a Numeric array (or something that can be converted to a Numeric array). """ def _add_item(item): if isinstance(item, PlotItems.PlotItem): self.itemlist.append(item) elif type(item) is types.StringType: self.itemlist.append(PlotItems.Func(item)) else: # assume data is an array: self.itemlist.append(PlotItems.Data(item)) for item in items: if type(item) is types.ListType: # assume it is a list of PlotItems for plot_item in item: _add_item(plot_item) else: # assume it is a regular PlotItem _add_item(item) #### CODE ENDS Essentially I moved the original functionality to "_add_item()", and I chech for each "item" whether it is really a PlotItem, or a list of PlotItems instead. Then I pass the data to "_add_item() accordingly. Anyways, hope this helps, -- Leo On Thu, 6 Nov 2003, Nate Gelbard wrote: > Hi, > > I have a database query that returns a variable length list of hosts for > which I want to plot some data about. > How can I pass Gnuplot.plot a list of Gnuplot.Data types? > In the past I knew how may lines I had on the graph so I could just pass > g.plot(gd1,gd2,gd3,gd4) .... how do I > make a variable length variable list? > > I was trying this but got a TypeError: bad argument type for built-in > operation > > plot_list = [] > for i in res.keys(): > print i > x = Numeric.arange(len(res[i]),typecode=Numeric.Float) > y = Numeric.zeros(len(res[i])) > for j in range(0,len(res[i])): > line = res[i] > y[j] = line[j][0] > gd = Gnuplot.Data(x,y,title=i,smooth=smoothtype) > plot_list.append(gd) > g.plot(plot_list) > > Thanks, > --( Nate Gelbard, QA Engineer > --( Tripwire, Inc., The Integrity Assurance Company |
From: <kai...@t-...> - 2003-11-08 21:28:38
|
This is easy using just Python features (no special support from Gnuplot.py required): Under any Python version: apply(g.plot, plot_list) Under recent Python versions (starting at 2.0?): g.plot(*plot_list) Either of these takes the elements of the sequence as individual arguments to the g.plot() method. Michael Nate Gelbard wrote: >I have a database query that returns a variable length list of hosts for >which I want to plot some data about. >How can I pass Gnuplot.plot a list of Gnuplot.Data types? >In the past I knew how may lines I had on the graph so I could just pass >g.plot(gd1,gd2,gd3,gd4) .... how do I >make a variable length variable list? > >I was trying this but got a TypeError: bad argument type for built-in >operation > > plot_list = [] > for i in res.keys(): > print i > x = Numeric.arange(len(res[i]),typecode=Numeric.Float) > y = Numeric.zeros(len(res[i])) > for j in range(0,len(res[i])): > line = res[i] > y[j] = line[j][0] > gd = Gnuplot.Data(x,y,title=i,smooth=smoothtype) > plot_list.append(gd) > g.plot(plot_list) > > -- Michael Haggerty mh...@al... |