2

I'm trying to implement the answer to this question: https://stackoverflow.com/questions/3704647/can-you-recommend-a-charting-library-for-scala/3704974#3704974

I've downloaded and compiled Scalala from the git hub and placed the scalala_2.8.1-1.0.0.RC2-SNAPSHOT.jar in my lib folder (I'm using SBT to do my build). Here's the code:

import scalala.library.Plotting
object ScalalaTest extends Application
{

  val x = Plotting.linspace(0,1);
}

I'm getting the following error:

[error] /src/main/scala/ScalalaTest.scala:6: value linspace is not a member of object scalala.library.Plotting
[error]   val x = Plotting.linspace(0,1);
[error]                    ^
[error] one error found

It looks like my scala compiler recognizes the scalala package but doesn't recognize members of Plotting (I've tried others besides linspace). This is strange because according to the Scalala API, linspace is a member of Plotting.

Community
  • 1
  • 1
dsg
  • 12,924
  • 21
  • 67
  • 111

2 Answers2

2

That used to work and was nice and elegant - it seems the current way is:

val x = DenseVector.range(0,100) / 100.0;
plot.hold = true
plot(x, x :^ 2)
plot(x, x :^ 3, '.')
xlabel("x axis")
ylabel("y axis")
saveas("lines.png")

This needs includes:

import scalala.tensor.dense.DenseVector
import scalala.library.Plotting._

The SBT dependencies are:

  val scalaToolsSnapshots = "Scala Tools Snapshots" at "http://scala-tools.org/repo-snapshots/"
  val ScalaNLPMaven2 = "ScalaNLP Maven2" at "http://repo.scalanlp.org/repo/"
  val ondex = "ondex" at "http://ondex.rothamsted.bbsrc.ac.uk/nexus/content/groups/public/"

  val scalala = "org.scalala" %% "scalala" % "1.0.0.RC2-SNAPSHOT"
Renaud
  • 16,073
  • 6
  • 81
  • 79
Johan Prinsloo
  • 1,188
  • 9
  • 9
  • @Johan Prinsloo -- What are the packages to import for this to work? – dsg May 21 '11 at 22:30
  • Import scalala.tensor.dense._ Tested with 1.0.0.RC2-SNAPSHOT – Johan Prinsloo May 21 '11 at 22:36
  • @Johan Prinsloo -- There's gotta be more. I'm still getting value not found on `plot`, `xlabel`, and `ylabel`. – dsg May 21 '11 at 22:52
  • tensor.dense._ is just for the new range method. Include scalala.library.Plotting._ + whetever else your code needs. I am using: import scalala.tensor.dense._ import scalala.library._ import scalala.library.Library._ import scalala.library.LinearAlgebra._ import scalala.library.Statistics._ import scalala.library.Plotting._ //import scalala.library.Vectors import scalala.operators.Implicits._ – Johan Prinsloo May 22 '11 at 00:56
  • @Johan Prinsloo -- I think something is wrong with my build. I get: `Vectors is not a member of scalala.library`. – dsg May 22 '11 at 05:05
  • The easiest way to make sure you get the correct stuff is top simply declare the dependency in a SBT build - I edited to include the correct dependencies - this works in SBT 0.7.7 – Johan Prinsloo May 23 '11 at 17:10
0

linspace seems to be a member of the trait Plotting, not of the companion object. So you'll have to create an instance of Plotting (or anything with Plotting) in order to access that method.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • `Plotting` has a companion: `object Plotting extends Plotting`. The other subclass is `scalala.Scalala`, which I'm having trouble referencing. The line `import scalala.Scalala` throws the following compiler error: `Scalala is not a member of scalala`. – dsg May 21 '11 at 07:00