2 # -*- coding: ISO-8859-1 -*-
5 # Copyright (C) 2002-2004 Jörg Lehmann <joergl@users.sourceforge.net>
6 # Copyright (C) 2003-2004 Michael Schindler <m-schindler@users.sourceforge.net>
7 # Copyright (C) 2002-2004 André Wobst <wobsta@users.sourceforge.net>
9 # This file is part of PyX (http://pyx.sourceforge.net/).
11 # PyX is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # PyX is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with PyX; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 import math
, re
, string
27 from pyx
import canvas
, path
, trafo
, unit
28 from pyx
.graph
.axis
import painter
, axis
31 goldenmean
= 0.5 * (math
.sqrt(5) + 1)
35 """an axispos linear along a line with a fix direction for the ticks"""
37 def __init__(self
, convert
, x1
, y1
, x2
, y2
, fixtickdirection
):
38 """initializes the instance
39 - only the convert method is needed from the axis
40 - x1, y1, x2, y2 are PyX lengths (start and end position of the line)
41 - fixtickdirection is a tuple tick direction (fixed along the line)"""
42 self
.convert
= convert
47 self
.x1_pt
= unit
.topt(x1
)
48 self
.y1_pt
= unit
.topt(y1
)
49 self
.x2_pt
= unit
.topt(x2
)
50 self
.y2_pt
= unit
.topt(y2
)
51 self
.fixtickdirection
= fixtickdirection
53 def vbasepath(self
, v1
=None, v2
=None):
58 return path
.line_pt((1-v1
)*self
.x1_pt
+v1
*self
.x2_pt
,
59 (1-v1
)*self
.y1_pt
+v1
*self
.y2_pt
,
60 (1-v2
)*self
.x1_pt
+v2
*self
.x2_pt
,
61 (1-v2
)*self
.y1_pt
+v2
*self
.y2_pt
)
63 def basepath(self
, x1
=None, x2
=None):
72 return path
.line_pt((1-v1
)*self
.x1_pt
+v1
*self
.x2_pt
,
73 (1-v1
)*self
.y1_pt
+v1
*self
.y2_pt
,
74 (1-v2
)*self
.x1_pt
+v2
*self
.x2_pt
,
75 (1-v2
)*self
.y1_pt
+v2
*self
.y2_pt
)
77 def gridpath(self
, x
):
78 raise RuntimeError("gridpath not available")
80 def vgridpath(self
, v
):
81 raise RuntimeError("gridpath not available")
83 def vtickpoint_pt(self
, v
):
84 return (1-v
)*self
.x1_pt
+v
*self
.x2_pt
, (1-v
)*self
.y1_pt
+v
*self
.y2_pt
86 def vtickpoint(self
, v
):
87 return (1-v
)*self
.x1
+v
*self
.x2
, (1-v
)*self
.y1
+v
*self
.y2
89 def tickpoint_pt(self
, x
):
91 return (1-v
)*self
.x1_pt
+v
*self
.x2_pt
, (1-v
)*self
.y1_pt
+v
*self
.y2_pt
93 def tickpoint(self
, x
):
95 return (1-v
)*self
.x1
+v
*self
.x2
, (1-v
)*self
.y1
+v
*self
.y2
97 def tickdirection(self
, x
):
98 return self
.fixtickdirection
100 def vtickdirection(self
, v
):
101 return self
.fixtickdirection
104 class lineaxisposlinegrid(lineaxispos
):
105 """an axispos linear along a line with a fix direction for the ticks
106 with support for grid lines for a rectangular graphs"""
108 __implements__
= painter
._Iaxispos
110 def __init__(self
, convert
, x1
, y1
, x2
, y2
, fixtickdirection
, startgridlength
, endgridlength
):
111 """initializes the instance
112 - only the convert method is needed from the axis
113 - x1, y1, x2, y2 are PyX lengths (start and end position of the line)
114 - fixtickdirection is a tuple tick direction (fixed along the line)
115 - startgridlength and endgridlength are PyX lengths for the starting
116 and end point of the grid, respectively; the gridpath is a line along
117 the fixtickdirection"""
118 lineaxispos
.__init
__(self
, convert
, x1
, y1
, x2
, y2
, fixtickdirection
)
119 self
.startgridlength
= startgridlength
120 self
.endgridlength
= endgridlength
121 self
.startgridlength_pt
= unit
.topt(self
.startgridlength
)
122 self
.endgridlength_pt
= unit
.topt(self
.endgridlength
)
124 def gridpath(self
, x
):
126 return path
.line_pt((1-v
)*self
.x1_pt
+v
*self
.x2_pt
+self
.fixtickdirection
[0]*self
.startgridlength_pt
,
127 (1-v
)*self
.y1_pt
+v
*self
.y2_pt
+self
.fixtickdirection
[1]*self
.startgridlength_pt
,
128 (1-v
)*self
.x1_pt
+v
*self
.x2_pt
+self
.fixtickdirection
[0]*self
.endgridlength_pt
,
129 (1-v
)*self
.y1_pt
+v
*self
.y2_pt
+self
.fixtickdirection
[1]*self
.endgridlength_pt
)
131 def vgridpath(self
, v
):
132 return path
.line_pt((1-v
)*self
.x1_pt
+v
*self
.x2_pt
+self
.fixtickdirection
[0]*self
.startgridlength_pt
,
133 (1-v
)*self
.y1_pt
+v
*self
.y2_pt
+self
.fixtickdirection
[1]*self
.startgridlength_pt
,
134 (1-v
)*self
.x1_pt
+v
*self
.x2_pt
+self
.fixtickdirection
[0]*self
.endgridlength_pt
,
135 (1-v
)*self
.y1_pt
+v
*self
.y2_pt
+self
.fixtickdirection
[1]*self
.endgridlength_pt
)
138 class graphxy(canvas
.canvas
):
140 def plot(self
, data
, styles
=None):
142 raise RuntimeError("layout setup was already performed")
151 raise RuntimeError() # TODO: default styles handling ...
154 style
= d
.defaultstyle
155 elif style
!= d
.defaultstyle
:
156 raise RuntimeError("defaultstyles differ")
158 d
.setstyles(self
, styles
)
159 self
.plotdata
.append(d
)
162 def pos_pt(self
, x
, y
, xaxis
=None, yaxis
=None):
164 xaxis
= self
.axes
["x"]
166 yaxis
= self
.axes
["y"]
167 return self
.xpos_pt
+ xaxis
.convert(x
)*self
.width_pt
, self
.ypos_pt
+ yaxis
.convert(y
)*self
.height_pt
169 def pos(self
, x
, y
, xaxis
=None, yaxis
=None):
171 xaxis
= self
.axes
["x"]
173 yaxis
= self
.axes
["y"]
174 return self
.xpos
+ xaxis
.convert(x
)*self
.width
, self
.ypos
+ yaxis
.convert(y
)*self
.height
176 def vpos_pt(self
, vx
, vy
):
177 return self
.xpos_pt
+ vx
*self
.width_pt
, self
.ypos_pt
+ vy
*self
.height_pt
179 def vpos(self
, vx
, vy
):
180 return self
.xpos
+ vx
*self
.width
, self
.ypos
+ vy
*self
.height
182 def vgeodesic(self
, vx1
, vy1
, vx2
, vy2
):
183 """returns a geodesic path between two points in graph coordinates"""
184 return path
.line_pt(self
.xpos_pt
+ vx1
*self
.width_pt
,
185 self
.ypos_pt
+ vy1
*self
.height_pt
,
186 self
.xpos_pt
+ vx2
*self
.width_pt
,
187 self
.ypos_pt
+ vy2
*self
.height_pt
)
189 def vgeodesic_el(self
, vx1
, vy1
, vx2
, vy2
):
190 """returns a geodesic path element between two points in graph coordinates"""
191 return path
.lineto_pt(self
.xpos_pt
+ vx2
*self
.width_pt
,
192 self
.ypos_pt
+ vy2
*self
.height_pt
)
194 def vcap_pt(self
, coordinate
, length_pt
, vx
, vy
):
195 """returns an error cap path for a given coordinate, lengths and
196 point in graph coordinates"""
198 return path
.line_pt(self
.xpos_pt
+ vx
*self
.width_pt
- 0.5*length_pt
,
199 self
.ypos_pt
+ vy
*self
.height_pt
,
200 self
.xpos_pt
+ vx
*self
.width_pt
+ 0.5*length_pt
,
201 self
.ypos_pt
+ vy
*self
.height_pt
)
202 elif coordinate
== 1:
203 return path
.line_pt(self
.xpos_pt
+ vx
*self
.width_pt
,
204 self
.ypos_pt
+ vy
*self
.height_pt
- 0.5*length_pt
,
205 self
.xpos_pt
+ vx
*self
.width_pt
,
206 self
.ypos_pt
+ vy
*self
.height_pt
+ 0.5*length_pt
)
208 raise ValueError("direction invalid")
210 def keynum(self
, key
):
212 while key
[0] in string
.letters
:
218 def removedomethod(self
, method
):
222 self
.domethods
.remove(method
)
228 if not self
.removedomethod(self
.dolayout
): return
230 # count the usage of styles and perform selects
232 def stylesid(styles
):
233 return ":".join([str(id(style
)) for style
in styles
])
234 for data
in self
.plotdata
:
236 styletotal
[stylesid(data
.styles
)] += 1
238 styletotal
[stylesid(data
.styles
)] = 1
240 for data
in self
.plotdata
:
242 styleindex
[stylesid(data
.styles
)] += 1
244 styleindex
[stylesid(data
.styles
)] = 0
245 data
.selectstyles(self
, styleindex
[stylesid(data
.styles
)], styletotal
[stylesid(data
.styles
)])
247 # adjust the axes ranges
248 for step
in range(3):
249 for data
in self
.plotdata
:
250 data
.adjustaxes(self
, step
)
253 XPattern
= re
.compile(r
"x([2-9]|[1-9][0-9]+)?$")
254 YPattern
= re
.compile(r
"y([2-9]|[1-9][0-9]+)?$")
255 xaxisextents
= [0, 0]
256 yaxisextents
= [0, 0]
257 needxaxisdist
= [0, 0]
258 needyaxisdist
= [0, 0]
259 items
= list(self
.axes
.items())
260 items
.sort() #TODO: alphabetical sorting breaks for axis numbers bigger than 9
261 # TODO: linked axes are not taken into account (consider x being a link to x2)
262 for key
, axis
in items
:
263 num
= self
.keynum(key
)
264 num2
= 1 - num
% 2 # x1 -> 0, x2 -> 1, x3 -> 0, x4 -> 1, ...
265 num3
= 2 * (num
% 2) - 1 # x1 -> 1, x2 -> -1, x3 -> 1, x4 -> -1, ...
266 if XPattern
.match(key
):
267 if needxaxisdist
[num2
]:
268 xaxisextents
[num2
] += self
.axesdist
269 self
.axespos
[key
] = lineaxisposlinegrid(axis
.convert
,
271 self
.ypos
+ num2
*self
.height
- num3
*xaxisextents
[num2
],
272 self
.xpos
+ self
.width
,
273 self
.ypos
+ num2
*self
.height
- num3
*xaxisextents
[num2
],
275 xaxisextents
[num2
], xaxisextents
[num2
] + self
.height
)
277 self
.xbasepath
= self
.axespos
[key
].basepath
278 self
.xvbasepath
= self
.axespos
[key
].vbasepath
279 self
.xgridpath
= self
.axespos
[key
].gridpath
280 self
.xvgridpath
= self
.axespos
[key
].vgridpath
281 self
.xtickpoint_pt
= self
.axespos
[key
].tickpoint_pt
282 self
.xtickpoint
= self
.axespos
[key
].tickpoint
283 self
.xvtickpoint_pt
= self
.axespos
[key
].vtickpoint_pt
284 self
.xvtickpoint
= self
.axespos
[key
].tickpoint
285 self
.xtickdirection
= self
.axespos
[key
].tickdirection
286 self
.xvtickdirection
= self
.axespos
[key
].vtickdirection
287 elif YPattern
.match(key
):
288 if needyaxisdist
[num2
]:
289 yaxisextents
[num2
] += self
.axesdist
290 self
.axespos
[key
] = lineaxisposlinegrid(axis
.convert
,
291 self
.xpos
+ num2
*self
.width
- num3
*yaxisextents
[num2
],
293 self
.xpos
+ num2
*self
.width
- num3
*yaxisextents
[num2
],
294 self
.ypos
+ self
.height
,
296 yaxisextents
[num2
], yaxisextents
[num2
] + self
.width
)
298 self
.ybasepath
= self
.axespos
[key
].basepath
299 self
.yvbasepath
= self
.axespos
[key
].vbasepath
300 self
.ygridpath
= self
.axespos
[key
].gridpath
301 self
.yvgridpath
= self
.axespos
[key
].vgridpath
302 self
.ytickpoint_pt
= self
.axespos
[key
].tickpoint_pt
303 self
.ytickpoint
= self
.axespos
[key
].tickpoint
304 self
.yvtickpoint_pt
= self
.axespos
[key
].vtickpoint_pt
305 self
.yvtickpoint
= self
.axespos
[key
].tickpoint
306 self
.ytickdirection
= self
.axespos
[key
].tickdirection
307 self
.yvtickdirection
= self
.axespos
[key
].vtickdirection
309 raise ValueError("Axis key '%s' not allowed" % key
)
310 axis
.finish(self
.axespos
[key
])
311 if XPattern
.match(key
):
312 xaxisextents
[num2
] += axis
.axiscanvas
.extent
313 needxaxisdist
[num2
] = 1
314 if YPattern
.match(key
):
315 yaxisextents
[num2
] += axis
.axiscanvas
.extent
316 needyaxisdist
[num2
] = 1
319 def dobackground(self
):
321 if not self
.removedomethod(self
.dobackground
): return
322 if self
.backgroundattrs
is not None:
323 self
.draw(path
.rect_pt(self
.xpos_pt
, self
.ypos_pt
, self
.width_pt
, self
.height_pt
),
324 self
.backgroundattrs
)
328 if not self
.removedomethod(self
.doaxes
): return
329 for axis
in self
.axes
.values():
330 self
.insert(axis
.axiscanvas
)
334 if not self
.removedomethod(self
.dodata
): return
335 for data
in self
.plotdata
:
340 if not self
.removedomethod(self
.dokey
): return
341 if self
.key
is not None:
342 c
= self
.key
.paint(self
.plotdata
)
344 def parentchildalign(pmin
, pmax
, cmin
, cmax
, pos
, dist
, inside
):
345 ppos
= pmin
+0.5*(cmax
-cmin
)+dist
+pos
*(pmax
-pmin
-cmax
+cmin
-2*dist
)
346 cpos
= 0.5*(cmin
+cmax
)+(1-inside
)*(1-2*pos
)*(cmax
-cmin
+2*dist
)
348 x
= parentchildalign(self
.xpos_pt
, self
.xpos_pt
+self
.width_pt
,
349 bbox
.llx_pt
, bbox
.urx_pt
,
350 self
.key
.hpos
, unit
.topt(self
.key
.hdist
), self
.key
.hinside
)
351 y
= parentchildalign(self
.ypos_pt
, self
.ypos_pt
+self
.height_pt
,
352 bbox
.lly_pt
, bbox
.ury_pt
,
353 self
.key
.vpos
, unit
.topt(self
.key
.vdist
), self
.key
.vinside
)
354 self
.insert(c
, [trafo
.translate_pt(x
, y
)])
357 while len(self
.domethods
):
360 def initwidthheight(self
, width
, height
, ratio
):
361 if (width
is not None) and (height
is None):
363 self
.height
= (1.0/ratio
) * self
.width
364 elif (height
is not None) and (width
is None):
366 self
.width
= ratio
* self
.height
370 self
.width_pt
= unit
.topt(self
.width
)
371 self
.height_pt
= unit
.topt(self
.height
)
372 if self
.width_pt
<= 0: raise ValueError("width <= 0")
373 if self
.height_pt
<= 0: raise ValueError("height <= 0")
375 def initaxes(self
, axes
, addlinkaxes
=0):
376 for key
in ["x", "y"]:
377 if not axes
.has_key(key
):
378 axes
[key
] = axis
.linear()
379 elif axes
[key
] is None:
382 if not axes
.has_key(key
+ "2") and axes
.has_key(key
):
383 axes
[key
+ "2"] = axes
[key
].createlinkaxis()
384 elif axes
[key
+ "2"] is None:
387 self
.axesnames
= ([], [])
388 for key
in axes
.keys():
389 if len(key
) != 1 and (not key
[1:].isdigit() or key
[1:] == "1"):
390 raise ValueError("invalid axis count")
392 self
.axesnames
[0].append(key
)
394 self
.axesnames
[1].append(key
)
396 raise ValueError("invalid axis name")
398 def __init__(self
, xpos
=0, ypos
=0, width
=None, height
=None, ratio
=goldenmean
,
399 key
=None, backgroundattrs
=None, axesdist
=0.8*unit
.v_cm
, **axes
):
400 canvas
.canvas
.__init
__(self
)
403 self
.xpos_pt
= unit
.topt(self
.xpos
)
404 self
.ypos_pt
= unit
.topt(self
.ypos
)
405 self
.initwidthheight(width
, height
, ratio
)
406 self
.initaxes(axes
, 1)
410 self
.backgroundattrs
= backgroundattrs
411 self
.axesdist
= axesdist
413 self
.domethods
= [self
.dolayout
, self
.dobackground
, self
.doaxes
, self
.dodata
, self
.dokey
]
419 return canvas
.canvas
.bbox(self
)
423 return canvas
.canvas
.prolog(self
)
425 def outputPS(self
, file):
427 canvas
.canvas
.outputPS(self
, file)
431 # some thoughts, but deferred right now
433 # class graphxyz(graphxy):
435 # axisnames = "x", "y", "z"
437 # def _vxtickpoint(self, axis, v):
438 # return self._vpos(v, axis.vypos, axis.vzpos)
440 # def _vytickpoint(self, axis, v):
441 # return self._vpos(axis.vxpos, v, axis.vzpos)
443 # def _vztickpoint(self, axis, v):
444 # return self._vpos(axis.vxpos, axis.vypos, v)
446 # def vxtickdirection(self, axis, v):
447 # x1, y1 = self._vpos(v, axis.vypos, axis.vzpos)
448 # x2, y2 = self._vpos(v, 0.5, 0)
449 # dx, dy = x1 - x2, y1 - y2
450 # norm = math.hypot(dx, dy)
451 # return dx/norm, dy/norm
453 # def vytickdirection(self, axis, v):
454 # x1, y1 = self._vpos(axis.vxpos, v, axis.vzpos)
455 # x2, y2 = self._vpos(0.5, v, 0)
456 # dx, dy = x1 - x2, y1 - y2
457 # norm = math.hypot(dx, dy)
458 # return dx/norm, dy/norm
460 # def vztickdirection(self, axis, v):
462 # x1, y1 = self._vpos(axis.vxpos, axis.vypos, v)
463 # x2, y2 = self._vpos(0.5, 0.5, v)
464 # dx, dy = x1 - x2, y1 - y2
465 # norm = math.hypot(dx, dy)
466 # return dx/norm, dy/norm
468 # def _pos(self, x, y, z, xaxis=None, yaxis=None, zaxis=None):
469 # if xaxis is None: xaxis = self.axes["x"]
470 # if yaxis is None: yaxis = self.axes["y"]
471 # if zaxis is None: zaxis = self.axes["z"]
472 # return self._vpos(xaxis.convert(x), yaxis.convert(y), zaxis.convert(z))
474 # def pos(self, x, y, z, xaxis=None, yaxis=None, zaxis=None):
475 # if xaxis is None: xaxis = self.axes["x"]
476 # if yaxis is None: yaxis = self.axes["y"]
477 # if zaxis is None: zaxis = self.axes["z"]
478 # return self.vpos(xaxis.convert(x), yaxis.convert(y), zaxis.convert(z))
480 # def _vpos(self, vx, vy, vz):
481 # x, y, z = (vx - 0.5)*self._depth, (vy - 0.5)*self._width, (vz - 0.5)*self._height
482 # d0 = float(self.a[0]*self.b[1]*(z-self.eye[2])
483 # + self.a[2]*self.b[0]*(y-self.eye[1])
484 # + self.a[1]*self.b[2]*(x-self.eye[0])
485 # - self.a[2]*self.b[1]*(x-self.eye[0])
486 # - self.a[0]*self.b[2]*(y-self.eye[1])
487 # - self.a[1]*self.b[0]*(z-self.eye[2]))
488 # da = (self.eye[0]*self.b[1]*(z-self.eye[2])
489 # + self.eye[2]*self.b[0]*(y-self.eye[1])
490 # + self.eye[1]*self.b[2]*(x-self.eye[0])
491 # - self.eye[2]*self.b[1]*(x-self.eye[0])
492 # - self.eye[0]*self.b[2]*(y-self.eye[1])
493 # - self.eye[1]*self.b[0]*(z-self.eye[2]))
494 # db = (self.a[0]*self.eye[1]*(z-self.eye[2])
495 # + self.a[2]*self.eye[0]*(y-self.eye[1])
496 # + self.a[1]*self.eye[2]*(x-self.eye[0])
497 # - self.a[2]*self.eye[1]*(x-self.eye[0])
498 # - self.a[0]*self.eye[2]*(y-self.eye[1])
499 # - self.a[1]*self.eye[0]*(z-self.eye[2]))
500 # return da/d0 + self._xpos, db/d0 + self._ypos
502 # def vpos(self, vx, vy, vz):
503 # tx, ty = self._vpos(vx, vy, vz)
504 # return unit.t_pt(tx), unit.t_pt(ty)
506 # def xbaseline(self, axis, x1, x2, xaxis=None):
507 # if xaxis is None: xaxis = self.axes["x"]
508 # return self.vxbaseline(axis, xaxis.convert(x1), xaxis.convert(x2))
510 # def ybaseline(self, axis, y1, y2, yaxis=None):
511 # if yaxis is None: yaxis = self.axes["y"]
512 # return self.vybaseline(axis, yaxis.convert(y1), yaxis.convert(y2))
514 # def zbaseline(self, axis, z1, z2, zaxis=None):
515 # if zaxis is None: zaxis = self.axes["z"]
516 # return self.vzbaseline(axis, zaxis.convert(z1), zaxis.convert(z2))
518 # def vxbaseline(self, axis, v1, v2):
519 # return (path._line(*(self._vpos(v1, 0, 0) + self._vpos(v2, 0, 0))) +
520 # path._line(*(self._vpos(v1, 0, 1) + self._vpos(v2, 0, 1))) +
521 # path._line(*(self._vpos(v1, 1, 1) + self._vpos(v2, 1, 1))) +
522 # path._line(*(self._vpos(v1, 1, 0) + self._vpos(v2, 1, 0))))
524 # def vybaseline(self, axis, v1, v2):
525 # return (path._line(*(self._vpos(0, v1, 0) + self._vpos(0, v2, 0))) +
526 # path._line(*(self._vpos(0, v1, 1) + self._vpos(0, v2, 1))) +
527 # path._line(*(self._vpos(1, v1, 1) + self._vpos(1, v2, 1))) +
528 # path._line(*(self._vpos(1, v1, 0) + self._vpos(1, v2, 0))))
530 # def vzbaseline(self, axis, v1, v2):
531 # return (path._line(*(self._vpos(0, 0, v1) + self._vpos(0, 0, v2))) +
532 # path._line(*(self._vpos(0, 1, v1) + self._vpos(0, 1, v2))) +
533 # path._line(*(self._vpos(1, 1, v1) + self._vpos(1, 1, v2))) +
534 # path._line(*(self._vpos(1, 0, v1) + self._vpos(1, 0, v2))))
536 # def xgridpath(self, x, xaxis=None):
538 # if xaxis is None: xaxis = self.axes["x"]
539 # v = xaxis.convert(x)
540 # return path._line(self._xpos+v*self._width, self._ypos,
541 # self._xpos+v*self._width, self._ypos+self._height)
543 # def ygridpath(self, y, yaxis=None):
545 # if yaxis is None: yaxis = self.axes["y"]
546 # v = yaxis.convert(y)
547 # return path._line(self._xpos, self._ypos+v*self._height,
548 # self._xpos+self._width, self._ypos+v*self._height)
550 # def zgridpath(self, z, zaxis=None):
552 # if zaxis is None: zaxis = self.axes["z"]
553 # v = zaxis.convert(z)
554 # return path._line(self._xpos, self._zpos+v*self._height,
555 # self._xpos+self._width, self._zpos+v*self._height)
557 # def vxgridpath(self, v):
558 # return path.path(path._moveto(*self._vpos(v, 0, 0)),
559 # path._lineto(*self._vpos(v, 0, 1)),
560 # path._lineto(*self._vpos(v, 1, 1)),
561 # path._lineto(*self._vpos(v, 1, 0)),
564 # def vygridpath(self, v):
565 # return path.path(path._moveto(*self._vpos(0, v, 0)),
566 # path._lineto(*self._vpos(0, v, 1)),
567 # path._lineto(*self._vpos(1, v, 1)),
568 # path._lineto(*self._vpos(1, v, 0)),
571 # def vzgridpath(self, v):
572 # return path.path(path._moveto(*self._vpos(0, 0, v)),
573 # path._lineto(*self._vpos(0, 1, v)),
574 # path._lineto(*self._vpos(1, 1, v)),
575 # path._lineto(*self._vpos(1, 0, v)),
578 # def _addpos(self, x, y, dx, dy):
582 # def _connect(self, x1, y1, x2, y2):
584 # return path._lineto(x2, y2)
588 # if not self.removedomethod(self.doaxes): return
589 # axesdist_pt = unit.topt(self.axesdist)
590 # XPattern = re.compile(r"%s([2-9]|[1-9][0-9]+)?$" % self.axisnames[0])
591 # YPattern = re.compile(r"%s([2-9]|[1-9][0-9]+)?$" % self.axisnames[1])
592 # ZPattern = re.compile(r"%s([2-9]|[1-9][0-9]+)?$" % self.axisnames[2])
593 # items = list(self.axes.items())
594 # items.sort() #TODO: alphabetical sorting breaks for axis numbers bigger than 9
595 # for key, axis in items:
596 # num = self.keynum(key)
597 # num2 = 1 - num % 2 # x1 -> 0, x2 -> 1, x3 -> 0, x4 -> 1, ...
598 # num3 = 1 - 2 * (num % 2) # x1 -> -1, x2 -> 1, x3 -> -1, x4 -> 1, ...
599 # if XPattern.match(key):
602 # axis._vtickpoint = self._vxtickpoint
603 # axis.vgridpath = self.vxgridpath
604 # axis.vbaseline = self.vxbaseline
605 # axis.vtickdirection = self.vxtickdirection
606 # elif YPattern.match(key):
609 # axis._vtickpoint = self._vytickpoint
610 # axis.vgridpath = self.vygridpath
611 # axis.vbaseline = self.vybaseline
612 # axis.vtickdirection = self.vytickdirection
613 # elif ZPattern.match(key):
616 # axis._vtickpoint = self._vztickpoint
617 # axis.vgridpath = self.vzgridpath
618 # axis.vbaseline = self.vzbaseline
619 # axis.vtickdirection = self.vztickdirection
621 # raise ValueError("Axis key '%s' not allowed" % key)
622 # if axis.painter is not None:
624 # # if XPattern.match(key):
625 # # self._xaxisextents[num2] += axis._extent
626 # # needxaxisdist[num2] = 1
627 # # if YPattern.match(key):
628 # # self._yaxisextents[num2] += axis._extent
629 # # needyaxisdist[num2] = 1
631 # def __init__(self, tex, xpos=0, ypos=0, width=None, height=None, depth=None,
632 # phi=30, theta=30, distance=1,
633 # backgroundattrs=None, axesdist=0.8*unit.v_cm, **axes):
634 # canvas.canvas.__init__(self)
638 # self._xpos = unit.topt(xpos)
639 # self._ypos = unit.topt(ypos)
640 # self._width = unit.topt(width)
641 # self._height = unit.topt(height)
642 # self._depth = unit.topt(depth)
644 # self.height = height
646 # if self._width <= 0: raise ValueError("width < 0")
647 # if self._height <= 0: raise ValueError("height < 0")
648 # if self._depth <= 0: raise ValueError("height < 0")
649 # self._distance = distance*math.sqrt(self._width*self._width+
650 # self._height*self._height+
651 # self._depth*self._depth)
652 # phi *= -math.pi/180
653 # theta *= math.pi/180
654 # self.a = (-math.sin(phi), math.cos(phi), 0)
655 # self.b = (-math.cos(phi)*math.sin(theta),
656 # -math.sin(phi)*math.sin(theta),
658 # self.eye = (self._distance*math.cos(phi)*math.cos(theta),
659 # self._distance*math.sin(phi)*math.cos(theta),
660 # self._distance*math.sin(theta))
661 # self.initaxes(axes)
662 # self.axesdist = axesdist
663 # self.backgroundattrs = backgroundattrs
666 # self.domethods = [self.dolayout, self.dobackground, self.doaxes, self.dodata]
668 # self.defaultstyle = {}
672 # return bbox._bbox(self._xpos - 200, self._ypos - 200, self._xpos + 200, self._ypos + 200)