aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/scalam/plotting/Plotter.scala
blob: cfd7b7ea322c049c9b15349fe6427e082a611382 (plain) (blame)
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
package scalam.plotting

import scalam.m._
import scalam.m.ast._
import scalam.plotting.styles._

trait Plotter {
  import Plotter._
  
  val pwd: scalax.file.Path
  
  lazy val interpreter = new MatlabInterpreter(pwd)
  
  def plot(dataSets: Seq[DataSet], title: String, x: String, y: String, grid: Boolean = true, legend: Boolean = true)(implicit styles: Seq[Style[_]] = defaultStyles, fontSize: FontSize =  defaultFontSize) = {
    val p = new Plot(dataSets, title, x, y, grid, legend, styles = styles, fontSize = fontSize.fontSize)
    p.save()
    val s = Evaluate(Function(Identifier("run"), StringLiteral((p.directory / p.localPlotFile).path)))
    //val s = "run '" + (p.directory / p.localPlotFile).path + "'"
    println(s.m)
    interpreter.evaluate(s)
  }
  
  def exit() {
    interpreter.write("exit")
    interpreter.close()
  }

}

object Plotter {
  val defaultStyles = Seq(color.JET, Uniform(marker.Plus), Uniform(line.Solid))
  val defaultFontSize = FontSize(16)
}