aboutsummaryrefslogblamecommitdiff
path: root/src/main/scala/scalam/plotting/Plotter.scala
blob: 0f9c1514f324db8eb5ecf56ce84a659ce5ca4be0 (plain) (tree)
1
2
3
4
5
6
7
8
9

                       

                     
                                           
                       

                                  
 
                                     

                  

                                                                                                                                                                                                                                                                


                                                                                       
                    

   





                                                                               
package scalam.plotting

import scalam.m._
import scalam.m.ast._
import scalam.m.interpretation.MInterpreter
import scalax.file.Path
import scalam.plotting.scale.Scale
import scalam.plotting.scale.Lin

trait Plotter { self: MInterpreter =>
  import Plotter._
  
  def plot(dataSets: Seq[DataSet], title: String, x: String, y: String, scales: (Scale, Scale) = (Lin, Lin), grid: Boolean = true, legend: Boolean = true)(implicit styles: Seq[Style[StyleElement]] = defaultStyles, fontSize: FontSize =  defaultFontSize) = {
    val plot = new Plot(dataSets, title, Axis(x, scales._1), Axis(y, scales._2), grid, legend, styles = styles, fontSize = fontSize.fontSize)
    val path = Path(Identifier.makeValid(title))
    scalam.io.save(plot, path)
    val s = Function(Identifier("run"), StringLiteral((path / Plot.PlotFileName).path))
    self.evaluate(s)
  }
  
}

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