Hi Alan,
On 08.03.06, Alan G Isaac wrote:
> OK, here's a different but possibly related question.
> I want one of my bars to have a different color than the rest.
> How best to do this?
Well, you could do a quick'n'dirty solution. (g.pos() might be of
great help here.)
But you can of course also do a real solution within the framework of
PyX. You would need to create an specialized bar style, which can
highlight some bars. See the enclosed example of what you'll need to
do for that. While it's quite straight forward, I'm aware of the fact
that you'll need to really go into the details on how graph styles
work. Still, there are no mysteries at all ...
André
--
by _ _ _ Dr. André Wobst
/ \ \ / ) [EMAIL PROTECTED], http://www.wobsta.de/
/ _ \ \/\/ / PyX - High quality PostScript and PDF figures
(_/ \_)_/\_/ with Python & TeX: visit http://pyx.sourceforge.net/
from pyx import *
class highlightbar(graph.style.bar):
defaulthighlightbarattrs = [color.palette.ReverseRainbow,
deco.stroked([color.grey.black, style.linewidth.THICK])]
def __init__(self, highlightbarattrs=[], **args):
self.highlightbarattrs = highlightbarattrs
graph.style.bar.__init__(self, **args)
def columnnames(self, privatedata, sharedata, agraph, columnnames):
if "highlight" not in columnnames:
raise ValueError("highlight missing")
return ["highlight"] + graph.style.bar.columnnames(self, privatedata,
sharedata, agraph, columnnames)
def selectstyle(self, privatedata, sharedata, agraph, selectindex,
selecttotal):
graph.style.bar.selectstyle(self, privatedata, sharedata, agraph,
selectindex, selecttotal)
privatedata.highlightbarattrs =
attr.selectattrs(self.defaulthighlightbarattrs + self.highlightbarattrs,
selectindex, selecttotal)
def drawpoint(self, privatedata, sharedata, agraph, point):
if point["highlight"]:
savebarattrs = privatedata.barattrs
privatedata.barattrs = privatedata.highlightbarattrs
graph.style.bar.drawpoint(self, privatedata, sharedata, agraph, point)
if point["highlight"]:
privatedata.barattrs = savebarattrs
g = graph.graphxy(width=8, x=graph.axis.bar())
g.plot(graph.data.list([["a", 1, False], ["b", 5, True], ["c", 9, False]],
xname=1, y=2, highlight=3), [highlightbar()])
g.writeEPSfile("minimal")