cleanups; all examples are working again
[PyX/mjg.git] / examples / graphs / washboard.py
blob55c4d48b58638f6426285132e9cd8e1a45b83ed1
1 # contributed by Sigmund Kohler
3 from math import pi, cos
4 from pyx import *
5 from pyx.deco import barrow, earrow
6 from pyx.style import linewidth, linestyle
7 from pyx.graph import graphxy, linaxis, axispainter, function, line
9 mypainter = axispainter(basepathattrs=earrow.normal(), titlepos=1)
10 def mycos(x): return -cos(x)+.10*x
12 g = graphxy(height=5, x2=None, y2=None,
13 x=linaxis(min=-2.5*pi, max=3.3*pi, part=None,
14 painter=mypainter, title=r"$\delta\phi$"),
15 y=linaxis(min=-2.3, max=2, painter=None))
16 g.plot(function("y=mycos(x)", context=locals()),
17 line(lineattrs=linewidth.Thick))
18 g.finish()
20 x1, y1 = g.pos(-pi+.1, mycos(-pi+.1))
21 x2, y2 = g.pos(-.1, mycos(-.1))
22 x3, y3 = g.pos(pi+.1, mycos(pi+.1))
24 g.stroke(path.line(x1-.5, y1, x1+.5, y1), linestyle.dashed)
25 g.stroke(path.line(x1-.5, y3, x3+.5, y3), linestyle.dashed)
26 g.stroke(path.line(x2-.5, y2, x3+.5, y2), linestyle.dashed)
27 g.stroke(path.line(x1, y1, x1, y3), barrow.normal(), earrow.normal())
28 g.stroke(path.line(x3, y2, x3, y3), barrow.normal(), earrow.normal())
29 g.text(x1+.2, 0.5*(y1+y3), r"$2\pi\gamma k\Omega$", text.vshift.middlezero)
30 g.text(x1-.6, y1-.1, r"$E_{\rm b}$", text.halign.right)
31 g.text(x3+.15, y2+.20, r"$2J_k(\varepsilon/\Omega)+\pi\gamma k\Omega$")
33 g.writetofile("washboard")