-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpolynomial.exs
47 lines (40 loc) · 1.03 KB
/
polynomial.exs
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
defmodule Polynomial do
@moduledoc """
Polynomials graphs from Wikipedia.
https://en.wikipedia.org/wiki/Polynomial#Graphs
"""
def png, do: Path.join("/tmp/", "polynomial.PNG")
def target,
do: [
[:set, :term, :pngcairo, :size, '400,400', :font, "Times,14"],
[:set, :output, png()]
]
def style,
do: [
~w(set style line 1 lw 3 lc '#DD0000')a,
~w(set style line 2 lw 3 lc '#000000')a,
~w(set style line 3 lw 1 lc '#CECECE')a,
~w(set xzeroaxis ls 2)a,
~w(set yzeroaxis ls 2)a,
~w(set grid ls 3)a,
[:set, :xrange, -5..4],
[:set, :yrange, -4..6],
[:set, :format, :x, ""],
[:set, :format, :y, ""],
~w(set border ls 3)a
]
def commands,
do: [
[:set, :title, "Wikipedia Polynomial"],
[
:plot,
'((x**3)/4)+(3*(x**2)/4)-(3*x/2)-2',
:ls,
1,
:notitle
]
]
def plot, do: {:ok, _} = Gnuplot.plot(target() ++ style() ++ commands())
end
# mix run examples/polynomial.exs
Polynomial.plot()