1

请帮助理解以下 Breeze 使用示例。下面的代码既有 Scala 对象方法调用,如等f.subplot(0)f.saveas也有函数调用:linspace(0.0,1.0), plot(x, x :^ 2.0).

像往常一样,生成的文档中描述了对象方法:http ://www.scalanlp.org/api/index.html#breeze.plot.Plot

问题:

1)我在哪里可以找到函数调用的规范:linspace(0.0,1.0)plot(x, x :^ 2.0)?据我所知,用于绘制 Breeze 使用 JFreeChart ( http://www.jfree.org/jfreechart/download.html )。也许这些是从 JFreeChart 包导入的 Java 对象linspaceplot

2) 是什么x :^ 3.0意思?

import breeze.plot._

val f = Figure()
val p = f.subplot(0)
val x = linspace(0.0,1.0)
p += plot(x, x :^ 2.0)
p += plot(x, x :^ 3.0, '.')
p.xlabel = "x axis"
p.ylabel = "y axis"
f.saveas("lines.png") // save current figure as a .png, eps and pdf also supported
4

1 回答 1

0

1您可以linspace在微风包对象中找到规范,linalg并且plot在包对象中plog

http://www.scalanlp.org/api/index.html#breeze.linalg.package https://github.com/scalanlp/breeze/blob/master/math/src/main/scala/breeze/linalg/package .scala#L127

  /**
   * Generates a vector of linearly spaced values between a and b (inclusive).
   * The returned vector will have length elements, defaulting to 100.
   */
  def linspace(a : Double, b : Double, length : Int = 100) : DenseVector[Double] = {
    val increment = (b - a) / (length - 1)
    DenseVector.tabulate(length)(i => a + increment * i)
  }

http://www.scalanlp.org/api/index.html#breeze.plot.package https://github.com/scalanlp/breeze/blob/master/viz/src/main/scala/breeze/plot/package .scala#L24

  /**
   * Plots the given y versus the given x with the given style.
   *
   * @param x X-coordinates, co-indexed with y (and indexed by keys of type K).
   * @param y Y-coordinates, co-indexed with x (and indexed by keys of type K).
   * @param style Matlab-like style spec of the series to plot.
   * @param name Name of the series to show in the legend.
   * @param labels Optional in-graph labels for some points.
   * @param tips Optional mouse-over tooltips for some points.
   */
  def plot[X,Y,V](x: X, y: Y, style : Char = '-', colorcode : String = null, name : String = null,
                  lines : Boolean = true, shapes : Boolean = false,
                  labels : (Int) => String = null.asInstanceOf[Int=>String],
                  tips : (Int) => String = null.asInstanceOf[Int=>String] )
                 (implicit xv: DomainFunction[X,Int,V],
                  yv: DomainFunction[Y, Int, V], vv: V=>Double):Series = new Series {
    ...

2这是逐元素取幂。因此x :^ 3.0将 x 与每个元素一起返回到三次方。在给出的示例中,x 是DenseVector介于 0 和 1 之间的 100 个值中的一个。因此x :^ 3.0会给您另一个DenseVector介于 0 和 1 之间的 100 个值,但它们被取为三次方,这是一个很好的图表。

于 2013-03-25T18:31:01.350 回答