graph style rework continues
[PyX/mjg.git] / examples / graphs / arrows.py
blob40394ebe126dab33727dd84d306f912bfe09ec95
1 from math import pi, atan2
2 from pyx import *
4 z1 = 2.5 + 4.5j
5 z2 = 7.5 + 5.5j
7 # we abuse a parametric function below, so we express everything in terms of a parameter k
8 x = lambda k: int(k)/11
9 y = lambda k: int(k)%11
10 z = lambda k: x(k) + y(k) * 1j
11 f = lambda k: 1/(z(k)-z1)/(z(k)-z2) # function to be plotted
12 s = lambda k: 5*abs(f(k)) # magnitude of function value
13 a = lambda k: 180/pi*atan2(f(k).imag, f(k).real) # direction of function value
15 g = graph.graphxy(width=8,
16 x=graph.axis.linear(min=0, max=10),
17 y=graph.axis.linear(min=0, max=10))
18 g.plot(graph.data.paramfunction("k", 0, 120,
19 "x, y, size, angle = x(k), y(k), s(k), a(k)",
20 points=121, context=locals()),# access extern
21 graph.style.arrow()) # variables&functions
22 g.writeEPSfile("arrows") # by passing a context