2 import sys
; sys
.path
[:0] = ["../.."]
9 def test_multiaxes_data(c
, x
, y
):
10 g
= c
.insert(graph
.graphxy(x
, y
, height
=5, key
=graph
.key
.key(pos
="tl"),
11 x
=graph
.axis
.log(title
="$W$", manualticks
=[graph
.axis
.tick
.tick(math
.sqrt(8)*100, label
="?"), graph
.axis
.tick
.tick(math
.sqrt(8), label
="$\sqrt{8}$")]),
12 y
=graph
.axis
.log(title
=r
"$PPP_1$",
13 painter
=graph
.axis
.painter
.regular(titledirection
=None)),
14 y2
=graph
.axis
.log(title
="$P_2$"),
15 y3
=graph
.axis
.log(title
="$PPP_3$",
16 painter
=graph
.axis
.painter
.regular(titledirection
=graph
.axis
.painter
.rotatetext(45), gridattrs
=[color
.palette
.RedGreen
]),
17 texter
=graph
.axis
.texter
.decimal(equalprecision
=1)),
18 y5
=graph
.axis
.log(title
="$P_5$")))
19 g
.plot((graph
.data
.file("data/testdata", x
=1, y
="sqrt(sqrt($3))", title
="mytitle"),
20 graph
.data
.file("data/testdata", x
=1, y2
=4),
21 graph
.data
.file("data/testdata", x
=1, y3
=5, title
=None),
22 graph
.data
.file("data/testdata", x
=1, y5
=6)),
23 styles
=[graph
.style
.symbol(symbolattrs
=[deco
.stroked
.clear
, color
.palette
.RedGreen
, graph
.style
.symbol
.changestrokedfilled
], symbol
=graph
.style
.symbol
.changesquaretwice
)])
26 def test_piaxis_function(c
, x
, y
):
27 xaxis
=graph
.axis
.lin(min=0, max=2*math
.pi
, divisor
=math
.pi
, texter
=graph
.axis
.texter
.rational(suffix
=r
"\pi"))
28 g
= c
.insert(graph
.graphxy(x
, y
, height
=5, x
=xaxis
))
29 #g = c.insert(graph.graphxy(x, y, height=5, x=xaxis, x2=xaxis))
30 g
.plot([graph
.data
.function("y(x)=sin(x-i*pi/10)", context
={"i": i
}) for i
in range(20)],
31 styles
=[graph
.style
.line(lineattrs
=[color
.palette
.Hue
])])
34 def test_textaxis_errorbars(c
, x
, y
):
35 g
= c
.insert(graph
.graphxy(x
, y
, height
=5,
36 x
=graph
.axis
.lin(min=0.5, max=12.5, parter
=graph
.axis
.parter
.lin("1", extendtick
=None)),
37 y
=graph
.axis
.lin(min=-10, max=30, title
="Temperature [$^\circ$C]"),
38 x2
=graph
.axis
.lin(painter
=graph
.axis
.painter
.regular(labelattrs
=None)), y2
=graph
.axis
.lin()))
39 g
.plot(graph
.data
.file("data/testdata2", x
=0, ymin
="min", ymax
="max"), [graph
.style
.errorbar()])
40 a
= graph
.style
.symbol
.triangle
41 g
.plot(graph
.data
.paramfunction("k", 0, 2*math
.pi
, "x2, y2, dx2, dy2 = 0.8*sin(k), 0.8*cos(3*k), 0.05, 0.05"), [graph
.style
.symbol(symbol
=a
), graph
.style
.errorbar()])
44 def test_ownmark(c
, x
, y
):
45 div
= lambda x
, y
: int(x
)/int(y
)
46 mod
= lambda x
, y
: int(x
)%int
(y
)
47 g
= c
.insert(graph
.graphxy(x
, y
, height
=5, x
=graph
.axis
.lin(min=0, max=10), y
=graph
.axis
.lin(min=0, max=10)))
48 g
.plot(graph
.data
.paramfunction("k", 0, 120, "x, y, size, angle = mod(k, 11), div(k, 11), (1+sin(k*pi/120))/2, 3*k", points
=121, context
=locals()), [graph
.style
.arrow()])
49 line1
= g
.plot(graph
.data
.function("y(x)= 10/x"))
50 line2
= g
.plot(graph
.data
.function("y(x)=12*x**-1.6"))
51 line3
= g
.plot(graph
.data
.function("y(x)=7/x"))
52 line4
= g
.plot(graph
.data
.function("y(x)=25*x**-1.6"))
53 g
.plot(graph
.data
.list([[-1, 1], [5, 2], [11, 5], [5, 11], [4, -1]], x
=1, y
=2), [graph
.style
.line(lineattrs
=[color
.rgb
.red
])])
57 p2
=line2
.path
.reversed()
58 p3
=line3
.path
.reversed()
60 (seg1a
,), (seg2a
,) = p1
.intersect(p2
)
61 (seg2b
,), (seg3b
,) = p2
.intersect(p3
)
62 (seg3c
,), (seg4c
,) = p3
.intersect(p4
)
63 (seg4d
,), (seg1d
,) = p4
.intersect(p1
)
64 area
= p1
.split([seg1a
, seg1d
])[1] << p4
.split([seg4d
, seg4c
])[1] << p3
.split([seg3c
, seg3b
])[1] << p2
.split([seg2b
, seg2a
])[1]
65 area
.normsubpaths
[-1].close()
66 g
.stroke(area
, [style
.linewidth
.THick
, deco
.filled([color
.gray(0.5)])])
68 def test_allerrorbars(c
, x
, y
):
69 g
= c
.insert(graph
.graphxy(x
, y
, height
=5, width
=5))
70 g
.plot(graph
.data
.file("data/testdata3", x
="x", y
="y", xmin
="xmin", xmax
="xmax", ymin
="ymin", ymax
="ymax", text
="text"), [graph
.style
.text(), graph
.style
.errorbar(), graph
.style
.symbol()])
73 def test_split(c
, x
, y
):
74 g
= c
.insert(graph
.graphxy(x
, y
, height
=5, width
=5,
76 y
=graph
.axis
.split()))
77 g
.plot(graph
.data
.file("data/testdata", x
=1, y
="splitatvalue($3, 0.005, 0.01, 0.015, 0.018)"))
80 def test_split2(c
, x
, y
):
81 g
= c
.insert(graph
.graphxy(x
, y
, height
=5, width
=5,
83 y
=graph
.axis
.split(subaxes
=[graph
.axis
.sizedlinear(size
=0.005), graph
.axis
.sizedlinear(size
=0.0025), graph
.axis
.autosizedlinear()], dist
=0.0025)))
84 g
.plot(graph
.data
.file("data/testdata", x
=1, y
="splitatvalue(0.0215-$3, 0.005, 0.01, 0.015, 0.015)"))
89 test_multiaxes_data(c
, 0, 21)
90 test_piaxis_function(c
, 0, 14)
91 test_textaxis_errorbars(c
, 0, 7)
93 test_allerrorbars(c
, -7, 0)
95 test_split2(c
, -7, 14)
97 c
.writeEPSfile("test_graph", paperformat
=document
.paperformat
.A4
)
98 c
.writePDFfile("test_graph", paperformat
=document
.paperformat
.A4
)