From: Andre W. <wo...@us...> - 2005-02-02 16:02:32
|
Hi Pieter, welcome on pyx-dev (which is kind of low traffic most of the time as pyx-user as well) ... ;-) On 02.02.05, pieter claassen wrote: > 1. Top plot this data so that it can be seen that there were 55 trips that > took 95 minutes and 45 minutes that took 100 minutes. > 2. To show that the distribution of the results are mostly on the high end. > > To recap the current problem: > When this large number of data points are plotted on a bar graph, the > x-axis labels overwrite each other. > > Current suggested solution: > ?? Well, not really. As I said before, you should try to use a x-y-plot for that. A bar graph is just the wrong thing for that. > Any suggestions on how to proceed? You'll need a histogram style. There are basically two ways to get it. You could create a style from graph.style.linestyle, overwrite the drawpoint method and call the graph.style.linestyle's drawpoint several times for each point with appropriately modified sharedata.vposi data to get the step-like shape. The other possibility would be to write your own style from scratch. A simple, first working example could look like: import random from pyx import * class histogram(graph.style._styleneedingpointpos): needsdata = ["vpos", "vposmissing", "vposavailable"] defaultlineattrs = [] def __init__(self, lineattrs=[]): self.lineattrs = lineattrs def selectstyle(self, privatedata, sharedata, graph, selectindex, selecttotal): if self.lineattrs is not None: privatedata.lineattrs = attr.selectattrs(self.defaultlineattrs + self.lineattrs, selectindex, selecttotal) else: privatedata.lineattrs = None def initdrawpoints(self, privatedata, sharedata, graph): privatedata.path = path.path() privatedata.lastvpos = None def drawpoint(self, privatedata, sharedata, graph): if sharedata.vposavailable: if privatedata.lastvpos: midvxpos = 0.5 * (privatedata.lastvpos[0] + sharedata.vpos[0]) privatedata.path.append(path.lineto_pt(*graph.vpos_pt(midvxpos, privatedata.lastvpos[1]))) privatedata.path.append(path.lineto_pt(*graph.vpos_pt(midvxpos, 0))) privatedata.path.append(path.lineto_pt(*graph.vpos_pt(midvxpos, sharedata.vpos[1]))) privatedata.path.append(path.lineto_pt(*graph.vpos_pt(*sharedata.vpos))) else: privatedata.path.append(path.moveto_pt(*graph.vpos_pt(*sharedata.vpos))) privatedata.lastvpos = sharedata.vpos[:] else: privatedata.lastvpos = None def donedrawpoints(self, privatedata, sharedata, graph): if privatedata.lineattrs is not None and len(privatedata.path.path): graph.stroke(privatedata.path, privatedata.lineattrs) g = graph.graphxy(width=8) g.plot(graph.data.list([(5*i, random.random()) for i in range(1, 20)], x=1, y=2), [histogram()]) g.writeEPSfile("histogram") However, its just a starting point. We do not correctly adjust the vertical range. We do not know how to handle the edge points (currently particial boxes are plotted --- we could, of course, just plot steps (like gnuplot and others, but I'm not sure whether this is a good idea)). We do not cut the path at the graph border. We can't exchange x and y axis ... etc. Any comments how to proceed? What's needed out there? (I do not need histograms at all, otherwise I would have implemented such a style before already, but since we're now on the subject, we might get it done once and for all ...) Although its working well that way, its not that easy to make it a robust graph style. As usual with graph styles. Its easy to implement one, but to make it general perpose, some more work needs to be done ... André -- by _ _ _ Dr. André Wobst / \ \ / ) wo...@us..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript figures with Python & TeX (_/ \_)_/\_/ visit http://pyx.sourceforge.net/ |