# HG changeset patch # User catherine@dellzilla # Date 1222716623 14400 # Node ID c03574f007df561dff1c4b79f33a36bce7dff893 # Parent 4927f901a634b4e48d13116d9a173eace68c754a it's so beautiful it makes me cry diff -r 4927f901a634 -r c03574f007df sqlpython/plothandler.py --- a/sqlpython/plothandler.py Mon Sep 29 14:50:31 2008 -0400 +++ b/sqlpython/plothandler.py Mon Sep 29 15:30:23 2008 -0400 @@ -1,4 +1,4 @@ -import shelve, pickle, cx_Oracle, datetime, sys +import shelve, pickle, cx_Oracle, datetime, sys, itertools shelvename = 'plot.shelve' try: @@ -38,32 +38,39 @@ self.draw() def bar(self): barEdges = pylab.arange(len(self.xvalues)) - width = 0.5 - for yseries in self.yserieslists: - pylab.bar(barEdges, yseries, width=width) - if self.xticks: - pylab.xticks(barEdges + (0.5 * width), self.xticks) + width = 0.5 / len(self.yserieslists) + colorcycler = itertools.cycle('rgb') + for (offset, yseries) in enumerate(self.yserieslists): + self.yplots.append(pylab.bar(barEdges + (offset*width), yseries, width=width, color=colorcycler.next())) + pylab.xticks(barEdges + 0.25, self.xticks or self.xvalues) def line(self, markers): for yseries in self.yserieslists: - pylab.plot(self.xvalues, yseries, markers) + self.yplots.append(pylab.plot(self.xvalues, yseries, markers)) if self.xticks: pylab.xticks(self.xvalues, self.xticks) - def draw(self, chartGuts, markers=None): + def pie(self): + self.yplots.append(pylab.pie(self.yserieslists[0], labels=self.xticks or self.xvalues)) + self.legends = [self.legends[0]] + def draw(self): if not self.yserieslists: print 'At least one quantitative column needed to plot.' return None - if self.outformat == '\\p': + self.yplots = [] + if self.outformat == '\\l': self.line('-o') - elif self.outformat == '\\P': + elif self.outformat == '\\L': self.line('-') + elif self.outformat == '\\p': + self.pie() else: self.bar() pylab.xlabel(self.xlabel) pylab.title(self.title) - pylab.legend(self.legends) + pylab.legend([p[0] for p in self.yplots], self.legends, shadow=True) pylab.show() print 'You can edit this plot from the command prompt (outside sqlpython) by running' print "ipython -pylab -c 'import sqlpython.plothandler; sqlpython.plothandler.Plot().unshelve()'" + print "See matplotlib documentation for editing instructions: http://matplotlib.sourceforge.net/" # there's got to be a way to install a shell script like that through setuptools... but how? except ImportError: diff -r 4927f901a634 -r c03574f007df sqlpython/sqlpyPlus.py --- a/sqlpython/sqlpyPlus.py Mon Sep 29 14:50:31 2008 -0400 +++ b/sqlpython/sqlpyPlus.py Mon Sep 29 15:30:23 2008 -0400 @@ -439,7 +439,7 @@ transpr[x][0] = rname newdesc[0][0] = 'COLUMN NAME' result = '\n' + sqlpython.pmatrix(transpr,newdesc) - elif outformat in ('\\p', '\\P', '\\b'): + elif outformat in ('\\l', '\\L', '\\p', '\\b'): plot = Plot() plot.build(self, outformat) plot.shelve() @@ -499,7 +499,7 @@ return completions rowlimitPattern = pyparsing.Word(pyparsing.nums)('rowlimit') - rawTerminators = '; \\s \\S \\c \\C \\t \\i \\p \\P \\b ' + ' '.join(output_templates.keys()) + rawTerminators = '; \\s \\S \\c \\C \\t \\i \\p \\l \\L \\b ' + ' '.join(output_templates.keys()) terminatorPattern = (pyparsing.oneOf(rawTerminators) ^ pyparsing.Literal('\n/') ^ \ (pyparsing.Literal('\nEOF') + pyparsing.stringEnd)) \ diff -r 4927f901a634 -r c03574f007df sqlpython/sqlpython.py --- a/sqlpython/sqlpython.py Mon Sep 29 14:50:31 2008 -0400 +++ b/sqlpython/sqlpython.py Mon Sep 29 15:30:23 2008 -0400 @@ -107,9 +107,10 @@ \\S CSV (no headings) \\t transposed \\x XML -\\p plot, with markers -\\P plot, lines only -\\b bar graph""" +\\l line plot, with markers +\\L line plot, lines only +\\b bar graph +\\p pie chart""" print self.do_terminators.__doc__ terminatorSearchString = '|'.join('\\' + d.split()[0] for d in do_terminators.__doc__.splitlines())