|
| 1 | +defmodule Polynomial do |
| 2 | + @moduledoc """ |
| 3 | + Polynomials graphs from Wikipedia. |
| 4 | +
|
| 5 | + https://en.wikipedia.org/wiki/Polynomial#Graphs |
| 6 | + """ |
| 7 | + |
| 8 | + def png, do: Path.join("/tmp/", "polynomial.PNG") |
| 9 | + |
| 10 | + def target, |
| 11 | + do: [ |
| 12 | + [:set, :term, :pngcairo, :size, '400,400', :font, "Times,14"], |
| 13 | + [:set, :output, png()] |
| 14 | + ] |
| 15 | + |
| 16 | + def style, |
| 17 | + do: [ |
| 18 | + ~w(set style line 1 lw 3 lc '#DD0000')a, |
| 19 | + ~w(set style line 2 lw 3 lc '#000000')a, |
| 20 | + ~w(set style line 3 lw 1 lc '#CECECE')a, |
| 21 | + ~w(set xzeroaxis ls 2)a, |
| 22 | + ~w(set yzeroaxis ls 2)a, |
| 23 | + ~w(set grid ls 3)a, |
| 24 | + [:set, :xrange, -5..4], |
| 25 | + [:set, :yrange, -4..6], |
| 26 | + [:set, :format, :x, ""], |
| 27 | + [:set, :format, :y, ""], |
| 28 | + ~w(set border ls 3)a |
| 29 | + ] |
| 30 | + |
| 31 | + def commands, |
| 32 | + do: [ |
| 33 | + [:set, :title, "Wikipedia Polynomial"], |
| 34 | + [ |
| 35 | + :plot, |
| 36 | + '((x**3)/4)+(3*(x**2)/4)-(3*x/2)-2', |
| 37 | + :ls, |
| 38 | + 1, |
| 39 | + :notitle |
| 40 | + ] |
| 41 | + ] |
| 42 | + |
| 43 | + def plot, do: {:ok, _} = Gnuplot.plot(target() ++ style() ++ commands()) |
| 44 | +end |
| 45 | + |
| 46 | +# mix run examples/polynomial.exs |
| 47 | +Polynomial.plot() |
0 commit comments