By Alvin Alexander. Last updated: June 28, 2019
If you want to use the JavaPlot library from the Scala REPL, it’s pretty easy to get started with. Just download and unpack the JavaPlot distribution and then find the JavaPlot.jar file in the dist directory of the package. Copy that jar file to the current directory, and then start a Scala REPL session like this:
$ scala -cp JavaPlot.jar Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51). Type in expressions to have them evaluated. Type :help for more information.
Next, just import the JavaPlot
class, create a new instance, and plot your heart out:
scala> import com.panayotis.gnuplot.JavaPlot import com.panayotis.gnuplot.JavaPlot scala> val p = new JavaPlot p: com.panayotis.gnuplot.JavaPlot = com.panayotis.gnuplot.JavaPlot@d3b11c3 scala> p.addPlot("sin(x)") scala> p.plot scala> p.addPlot("cos(x)") scala> p.plot
Those series of commands creates this plot:
There isn’t much documentation with JavaPlot, but you can find more examples in the demo/src/demo.java file of the distribution.
For more information on using JavaPlot, see the JavaPlot website. JavaPlot is a wrapper around Gnuplot, which I wrote about in my collection of Gnuplot examples.