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 |