From: Sybren <sy...@st...> - 2006-08-03 11:28:30
|
Hi folks, I want to upgrade from 0.8.1 to 0.9. However, I have code that refuses to work with the new version. Could any of you please have a look at it and tell me what I should change? Thanks a lot in advance! Sorry for the Dutch by the way, but the code is part of a Dutch financial calculation package. "Jaartal" means "year" "Aanwezig inkomen" means "Available income" "Gewenst inkomen" means "Wanted income" "Tekort" means "Short" The code: def plotbars(filename, *args): '''Plots een bargraph. De grafiek wordt opgeslagen als EPS in de file genaamd 'filename'. De argumenten moeten tuples zijn van vier waarden: - Jaartal - Aanwezig inkomen - Gewenst inkomen - Tekort ''' log.debug('Plotting graph in "%s"' % filename) # Create the graph, with the proper colours and key. palette = UPNPalette() mynestedbaraxis = pyx.graph.axis.bar( defaultsubaxis=pyx.graph.axis.bar( dist=0.2, painter=None ) ) key = pyx.graph.key.key(hinside=0) texter = pyx.graph.axis.texter.decimal() g = pyx.graph.graphxy( width=8, x=mynestedbaraxis, y=pyx.graph.axis.linear(texter=texter), key=key ) aanwezig_data = [(a[0], a[1]) for a in args] gewenst_data = [(a[0], a[2]) for a in args] tekort_data = [(a[0], a[3]) for a in args] # Build a list data lists gewenst = pyx.graph.data.list(gewenst_data, xname=1, y=2, title='Gewenst') aanwezig = pyx.graph.data.list(aanwezig_data,xname=1, y=2, title='Aanwezig') tekort = pyx.graph.data.list(tekort_data, xname=1, y=2, title='Tekort') # Draw the graph g.plot([gewenst, aanwezig, tekort], [ pyx.graph.style.barpos(fromvalue=0), pyx.graph.style.bar([palette]) ]) # Write the EPS g.writeEPSfile(filename) def main(): plot = plotbars('plot1', (2030, 12410, 93021, -3020), (2031, 12410, 93021, -3020), (2036, 12410, 93021, -3020) ) The error message: File "/home/sybren/live-20060616-1017/upn/plotter/__init__.py", line 87, in plotbars g.writeEPSfile(filename) File "/home/sybren/packages/PyX-0.9/pyx/canvas.py", line 329, in wrappedindocument return method(d, file) File "/home/sybren/packages/PyX-0.9/pyx/document.py", line 155, in writeEPSfile pswriter.epswriter(self, file, *args, **kwargs) File "/home/sybren/packages/PyX-0.9/pyx/pswriter.py", line 278, in __init__ page.processPS(pagefile, self, acontext, registry, pagebbox) File "/home/sybren/packages/PyX-0.9/pyx/document.py", line 138, in processPS self._process("processPS", *args) File "/home/sybren/packages/PyX-0.9/pyx/document.py", line 81, in _process getattr(self.canvas, processMethod)(canvasfile, writer, context, registry, bbox) File "/home/sybren/packages/PyX-0.9/pyx/graph/graph.py", line 157, in processPS self.finish() File "/home/sybren/packages/PyX-0.9/pyx/graph/graph.py", line 250, in finish self.doaxes() File "/home/sybren/packages/PyX-0.9/pyx/graph/graph.py", line 472, in doaxes self.dolayout() File "/home/sybren/packages/PyX-0.9/pyx/graph/graph.py", line 456, in dolayout self.doaxiscreate(axisname) File "/home/sybren/packages/PyX-0.9/pyx/graph/graph.py", line 449, in doaxiscreate self.doaxispositioner(axisname) File "/home/sybren/packages/PyX-0.9/pyx/graph/graph.py", line 411, in doaxispositioner self.doranges() File "/home/sybren/packages/PyX-0.9/pyx/graph/graph.py", line 200, in doranges plotitem.adjustaxesstatic(self) File "/home/sybren/packages/PyX-0.9/pyx/graph/graph.py", line 79, in adjustaxesstatic style.adjustaxis(privatedata, self.sharedata, graph, columnname, data) File "/home/sybren/packages/PyX-0.9/pyx/graph/style.py", line 1249, in adjustaxis graph.axes[sharedata.barposcolumnnames[i][:-4]].adjustaxis([self.addsubvalue(x, 0) for x in data]) File "/home/sybren/packages/PyX-0.9/pyx/graph/axis/axis.py", line 512, in adjustaxis self.axis.adjustaxis(self.data, columndata, self.graphtexrunner, self.errorname) File "/home/sybren/packages/PyX-0.9/pyx/graph/axis/axis.py", line 364, in adjustaxis "%s, subaxis %s" % (errorname, name)) File "/home/sybren/packages/PyX-0.9/pyx/graph/axis/axis.py", line 341, in adjustaxis raise ValueError("tuple expected by bar axis '%s'" % errorname) ValueError: tuple expected by bar axis 'x, subaxis 2018' Again, thanks to anyone willing to help. -- Sybren Stüvel, B.Sc. Stüvel IT http://www.stuvel.eu/ |
From: Andre W. <wo...@us...> - 2006-08-03 11:50:45
|
Hi Sybren, yeah, I'm sorry about this incompatible change. It was a serious problem which needed to be fixed. See http://sourceforge.net/mailarchive/message.php?msg_id=34318807 for some comments about that. Your case requires a quite minimal change: You just have to create the proper tuples in the data lists. Let me show you this in the quoted source: On 03.08.06, Sybren Stüvel wrote: > def plotbars(filename, *args): > '''Plots een bargraph. > > De grafiek wordt opgeslagen als EPS in de file genaamd 'filename'. > > De argumenten moeten tuples zijn van vier waarden: > - Jaartal > - Aanwezig inkomen > - Gewenst inkomen > - Tekort > ''' > > log.debug('Plotting graph in "%s"' % filename) > > # Create the graph, with the proper colours and key. > palette = UPNPalette() > mynestedbaraxis = pyx.graph.axis.bar( > defaultsubaxis=pyx.graph.axis.bar( > dist=0.2, > painter=None > ) > ) > key = pyx.graph.key.key(hinside=0) > texter = pyx.graph.axis.texter.decimal() > g = pyx.graph.graphxy( > width=8, > x=mynestedbaraxis, > y=pyx.graph.axis.linear(texter=texter), > key=key > ) > > aanwezig_data = [(a[0], a[1]) for a in args] > gewenst_data = [(a[0], a[2]) for a in args] > tekort_data = [(a[0], a[3]) for a in args] aanwezig_data = [((a[0], 0), a[1]) for a in args] gewenst_data = [((a[0], 1), a[2]) for a in args] tekort_data = [((a[0], 2), a[3]) for a in args] > > # Build a list data lists > gewenst = pyx.graph.data.list(gewenst_data, xname=1, y=2, title='Gewenst') > aanwezig = pyx.graph.data.list(aanwezig_data,xname=1, y=2, title='Aanwezig') > tekort = pyx.graph.data.list(tekort_data, xname=1, y=2, title='Tekort') > > # Draw the graph > g.plot([gewenst, aanwezig, tekort], > [ > pyx.graph.style.barpos(fromvalue=0), > pyx.graph.style.bar([palette]) > ]) > > # Write the EPS > g.writeEPSfile(filename) > > def main(): > plot = plotbars('plot1', > (2030, 12410, 93021, -3020), > (2031, 12410, 93021, -3020), > (2036, 12410, 93021, -3020) > ) HTH, André -- by _ _ _ Dr. André Wobst / \ \ / ) wo...@us..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript and PDF figures (_/ \_)_/\_/ with Python & TeX: visit http://pyx.sourceforge.net/ |
From: Sybren <sy...@st...> - 2006-08-03 12:01:13
|
Hi Andre, On Thu, Aug 03, 2006 at 01:50:38PM +0200, Andre Wobst wrote: > yeah, I'm sorry about this incompatible change. It was a serious > problem which needed to be fixed. See > http://sourceforge.net/mailarchive/message.php?msg_id=3D34318807 for > some comments about that. What is broken needs to be fixed :) > Your case requires a quite minimal change: You just have to create > the proper tuples in the data lists. Let me show you this in the > quoted source: Thanks a bunch! I'm very happy with PyX, and the mailing list is good too. What sometimes annoys me, though, are the cryptic or short error messages. For example, I got a message "Error writing to file" or something along that line. It would be much more useful if the error message included the file to which it couldn't write. Often I'm stuck with something like "expecting tuple", while there is no good documentation on passing data to PyX - 99% of all examples read from a file instead of giving data-passing examples in Python. Greetings, --=20 Sybren St=FCvel, B.Sc. St=FCvel IT http://www.stuvel.eu/ |
From: Joerg L. <jo...@us...> - 2006-08-03 12:07:47
|
Hi Sybren, On 03.08.06, Sybren Stüvel wrote: > Often I'm stuck with > something like "expecting tuple", while there is no good documentation > on passing data to PyX - 99% of all examples read from a file instead > of giving data-passing examples in Python. Thanks for mentioning that. I already had in mind to write some example on howto do this, so expect some improvement in this regard for the next release. Jörg |