From bc6961239476faaa6b43f42a261c90afb6fb224e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Wobst?= Date: Fri, 2 Jul 2004 08:42:45 +0000 Subject: [PATCH] graph data: minor corrections + paramfunc git-svn-id: https://pyx.svn.sourceforge.net/svnroot/pyx/trunk/pyx@1784 069f4177-920e-0410-937b-c2a4a81bcd90 --- pyx/graph/axis/axis.py | 4 +- pyx/graph/data.py | 137 ++++++++++++++++++------------------------ test/functional/test_graph.py | 8 +-- 3 files changed, 66 insertions(+), 83 deletions(-) diff --git a/pyx/graph/axis/axis.py b/pyx/graph/axis/axis.py index df89b293..1c619f5c 100644 --- a/pyx/graph/axis/axis.py +++ b/pyx/graph/axis/axis.py @@ -254,12 +254,12 @@ class _axis: for point, maxpoint in zip(data, deltamaxdata): try: if index is not None: - if deltaminindex is not None: + if deltamaxindex is not None: value = point[index] + maxpoint[deltamaxindex] + self.zero else: value = point[index] + maxpoint + self.zero else: - if deltaminindex is not None: + if deltamaxindex is not None: value = point + maxpoint[deltamaxindex] + self.zero else: value = point + maxpoint + self.zero diff --git a/pyx/graph/data.py b/pyx/graph/data.py index 69554bd3..42a35359 100644 --- a/pyx/graph/data.py +++ b/pyx/graph/data.py @@ -145,27 +145,7 @@ class _data(_Idata): defaultstyles = [style.symbol()] def getcolumndataindex(self, column): - try: - if self.addlinenumbers: - index = self.columns[column]-1 - else: - index = self.columns[column] - except KeyError: - try: - if type(column) != type(column + 0): - raise ValueError("integer expected") - except: - raise ValueError("integer expected") - if self.addlinenumbers: - if column > 0: - index = column-1 - elif column < 0: - index = column - else: - return range(1, 1+len(self.data)), None - else: - index = column - return self.data, index + return self.data, self.columns[column] def getcount(self): return len(self.data) @@ -252,6 +232,29 @@ class _data(_Idata): class list(_data): "Graph data from a list of points" + def getcolumndataindex(self, column): + try: + if self.addlinenumbers: + index = self.columns[column]-1 + else: + index = self.columns[column] + except KeyError: + try: + if type(column) != type(column + 0): + raise ValueError("integer expected") + except: + raise ValueError("integer expected") + if self.addlinenumbers: + if column > 0: + index = column-1 + elif column < 0: + index = column + else: + return range(1, 1+len(self.data)), None + else: + index = column + return self.data, index + def __init__(self, data, title="user provided list", addlinenumbers=1, **columns): if len(data): # be paranoid and check each row to have the same number of data @@ -571,14 +574,19 @@ class conffile(data): data.__init__(self, readfile(filename, "user provided file-like object"), **kwargs) +class _linedata(_data): + + defaultstyle = [style.line()] + + # class function: # # defaultstyle = style.line() # -# def __init__(self, expression, title=notitle, min=None, max=None, +# def __init__(self, expression, title=_notitle, min=None, max=None, # points=100, parser=mathtree.parser(), context={}): # -# if title is notitle: +# if title is _notitle: # self.title = expression # else: # self.title = title @@ -663,58 +671,33 @@ class conffile(data): # style.drawpoint(graph, self.styledata) # for style in self.styles: # style.donedrawpoints(graph, self.styledata) -# -# -# class paramfunction: -# -# defaultstyle = style.line() -# -# def __init__(self, varname, min, max, expression, title=notitle, points=100, parser=mathtree.parser(), context={}): -# if title is notitle: -# self.title = expression -# else: -# self.title = title -# self.varname = varname -# self.min = min -# self.max = max -# self.numberofpoints = points -# self.expression = {} -# varlist, expressionlist = expression.split("=") -# keys = varlist.split(",") -# mathtrees = parser.parse(expressionlist) -# if len(keys) != len(mathtrees): -# raise ValueError("unpack tuple of wrong size") -# self.points = [None]*self.numberofpoints -# emptyresult = [None]*len(keys) -# self.columns = {} -# i = 1 -# for key in keys: -# self.columns[key.strip()] = i -# i += 1 -# for i in range(self.numberofpoints): -# param = self.min + (self.max-self.min)*i / (self.numberofpoints-1.0) -# context[self.varname] = param -# self.points[i] = [param] + emptyresult -# column = 1 -# for key, column in self.columns.items(): -# self.points[i][column] = mathtrees[column-1].Calc(**context) -# column += 1 -# -# def setstyles(self, graph, style): -# self.style = style -# unhandledcolumns = self.style.setdata(graph, self.columns, self.styledata) -# unhandledcolumnkeys = unhandledcolumns.keys() -# if len(unhandledcolumnkeys): -# raise ValueError("style couldn't handle column keys %s" % unhandledcolumnkeys) -# -# def selectstyles(self, graph, selectindex, selecttotal): -# self.style.selectstyle(selectindex, selecttotal, self.styledata) -# -# def adjustaxes(self, graph, step): -# if step == 0: -# self.style.adjustaxes(self.points, self.columns.values(), self.styledata) -# -# def draw(self, graph): -# raise # TODO -# self.style.drawpoints(self.points, graph, self.styledata) + + +class paramfunction(_linedata): + + def __init__(self, varname, min, max, expression, title=_notitle, points=100, parser=mathtree.parser(), context={}): + if title is _notitle: + self.title = expression + else: + self.title = title + varlist, expressionlist = expression.split("=") + keys = varlist.split(",") + mathtrees = parser.parse(expressionlist) + if len(keys) != len(mathtrees): + raise ValueError("unpack tuple of wrong size") + self.data = [None]*points + emptyresult = [None]*len(keys) + self.columns = {} + i = 1 + for key in keys: + self.columns[key.strip()] = i + i += 1 + for i in range(points): + param = min + (max-min)*i / (points-1.0) + context[varname] = param + self.data[i] = [param] + emptyresult + column = 1 + for key, column in self.columns.items(): + self.data[i][column] = mathtrees[column-1].Calc(**context) + column += 1 diff --git a/test/functional/test_graph.py b/test/functional/test_graph.py index d315d7ee..da059020 100755 --- a/test/functional/test_graph.py +++ b/test/functional/test_graph.py @@ -35,10 +35,10 @@ def test_piaxis_function(c, x, y): def test_textaxis_errorbars(c, x, y): g = c.insert(graph.graphxy(x, y, height=5, x=graph.axis.lin(min=0.5, max=12.5, parter=graph.axis.parter.lin("1", extendtick=None)), - y=graph.axis.lin(title="Temperature [$^\circ$C]"), - ))#x2=graph.axis.lin(), y2=graph.axis.lin())) - g.plot(graph.data.file("data/testdata2", x=0, ymin="min", ymax="max"), [graph.style.errorbar()]) - #g.plot(graph.data.paramfunction("k", 0, 2*math.pi, "x2, y2, dx2, dy2 = 0.8*sin(k), 0.8*cos(3*k), 0.05, 0.05"), [graph.style.pointpos(), graph.style.rangepos(), graph.style.symbol(symbol=graph.style.symbol.triangle), graph.style.errorbar()]) + y=graph.axis.lin(min=-10, max=30, title="Temperature [$^\circ$C]"), + x2=graph.axis.lin(), y2=graph.axis.lin())) + #g.plot(graph.data.file("data/testdata2", x=0, ymin="min", ymax="max"), [graph.style.errorbar()]) + g.plot(graph.data.paramfunction("k", 0, 2*math.pi, "x2, y2, dx2, dy2 = 0.8*sin(k), 0.8*cos(3*k), 0.05, 0.05"), [graph.style.symbol(symbol=graph.style._trianglesymbol), graph.style.errorbar()]) g.finish() def test_ownmark(c, x, y): -- 2.11.4.GIT