-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hawk.jl
63 lines (52 loc) · 1.47 KB
/
Hawk.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
module Hawk
import PyPlot
using PyCall
filename = abspath(joinpath(dirname(@__FILE__),"Hawk.py"))
if PyCall.pyversion < v"3"
@pyimport imp
(path, name) = dirname(filename), basename(filename)
(name, ext) = rsplit(name, '.', 2)
(file, filename, data) = imp.find_module(name, [path])
Hawkpy = imp.load_module(name, file, filename, data)
else
@pyimport importlib.machinery as machinery
#The pyimport is not used due to Hawk.py is not in path
loader = machinery.SourceFileLoader("test",filename)
Hawkpy = loader[:load_module]("test")
end
export @constants, latexplot
macro constants(exprs)
for (i,exp) in enumerate(exprs.args)
if exp.head==:(=)
exprs.args[i] = Expr(:const,exp)
end
end
return esc(exprs)
end
"`latexplot` changes the setting for a plot to fit latex layout
The functions first argument is the size given as a ration of page width.
An optional keyword argument aspect_ratio ratio can be given.
```
#settings applies to all plots after this command
latexplot(ratio, aspect_ratio=(sqrt(5)-1.0)/2)
#setting only apply to the plot before the end
latexplot(ratio, aspect_ratio=(sqrt(5)-1.0)/2) do
plot(1:10)
end
```
"
function latexplot(args...; kws...)
Hawkpy[:latexplot](args...; kws...)
end
function latexplot(f::Function, args...; kws...)
Hawkpy[:latexplot](args...; kws...)
try
f()
finally
latexplot_reset()
end
end
function latexplot_reset()
Hawkpy[:latexplot_reset]()
end
end # module