In addition to the other problems,when I have a graph where there are
four columns of equal value, none of them are displayed.
On Thu, 15 Jun 2006 11:11:07 -0600
trevorw <[EMAIL PROTECTED]> wrote:
> First, I should apologize for being a troll on this list, I post
> questions but no answers. Sorry. I'm still learning and thus am not
> really qualified to help in answering any questions yet. Thanks for
your
> patience and help.
>
> Some time back I asked about plotting bar graphs with different
colours.
> I managed to adapt the code and it is working nicely for me.
>
> I have two issues. Right now, my chart is being produced in a
horizontal
> format and I'm using \rotatebox in LaTeX to orient it the way I want.
I
> would prefer to produce with horizontal bars.
>
> Second, is that the number of bars on different graphs changes, and
> there are subtle variations in the size of the horizontal bars. This
> code is being used to produce a book in which some graphs will have
only
> 2 or 3 bars and others will have 10 or 12. I need the bars and font
> sizes to remain constant. Any suggestions?
>
> This is my current code:
>
> # import data
> d = graph.data.list(habdata, title="habitat data", lineno=0,
> habitat=1, use=2, C=3, M=4, Y=5, K=6)
>
> # determine number of bars
> barcount=len(d.columns["C"])
>
> barmax = max(d.columns["use"])*1.2
>
> barwidth = barcount
> barheight = 5
>
> # create data list tailored to meet this data set
> datalist = [(d.columns["habitat"][x],d.columns["use"][x],True,
> graph.style.bar([color.cmyk(d.columns["C"][x],d.columns["M"][x],
> d.columns["Y"][x],
> d.columns["K"][x]),]),barmax, '%d\%%' %
> (d.columns["use"][x])) for x in range(0, barcount)]
> # NOTE: must use escape character to keep percent sign
> # from being interpreted as a format string
>
> # prepare the graphbarcount*1.1
> g = graph.graphxy(width=barwidth, height=barheight,
> x=graph.axis.bar(painter=graph.axis.painter.bar(
>
nameattrs=[trafo.rotate(90),text.halign.right,text.size.Large],
> basepathattrs=None)), y=graph.axis.linear(painter=None),
> y2=None, x2=None)
> # plot it
> g.plot(graph.data.list(datalist,
> xname=1,y=2,multistyle=3,barstyle=4, stack=5,stacktext=6),
> [multistylebar(),
> graph.style.stackedbarpos("stack"),
> graph.style.bar([color.cmyk(0.0, 0.0, 0.0,
> 0.0),deco.stroked.clear]),
>
graph.style.text("stacktext",textattrs=[trafo.rotate(90),text.halign.bo
> xright,text.size.Large])])
> # write to a file
> outfile = string.join([graphdir,
> "/",string.lower(speciescode),"_habitats.eps"],'')
> g.writeEPSfile(outfile)
>
>
> FYI my multibar() class is as follows:
> from pyx import *
>
> # Define class that allows for bars with individual styles
>
> class multistylebar(graph.style.bar):
>
> defaultmultistylebarattrs = [color.palette.ReverseRainbow,
> deco.stroked([color.grey.black, style.linewidth.THICK])]
>
> def __init__(self, multistylebarattrs=[], **args):
> self.multistylebarattrs = multistylebarattrs
> graph.style.bar.__init__(self, **args)
>
> def columnnames(self, privatedata, sharedata, agraph,
columnnames):
> if "multistyle" not in columnnames:
> raise ValueError("multistyle missing")
> if "barstyle" not in columnnames:
> raise ValueError("barstyle missing")
> return ["multistyle"] + ["barstyle"] +
> 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.multistylebarattrs =
> attr.selectattrs(self.defaultmultistylebarattrs +
> self.multistylebarattrs, selectindex, selecttotal)
>
> def drawpoint(self, privatedata, sharedata, agraph, point):
> if point["multistyle"]:
> savebarattrs = privatedata.barattrs
> privatedata.barattrs = point["barstyle"].barattrs
> graph.style.bar.drawpoint(self, privatedata, sharedata,
agraph,
> point) if point["multistyle"]:
> privatedata.barattrs = savebarattrs
>
> --
> Trevor Wiens
>
>
> _______________________________________________
> PyX-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pyx-user
--
Trevor Wiens
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user