Breeze-viz reference

Writing a reference in a programming book is a dangerous exercise: you quickly become out of date. Nevertheless, given the paucity of documentation for breeze-viz, this section becomes more relevant – it is easier to compete against something that does not exist. Take this section with a pinch of salt, and if a command in this section does not work, head over to the source code:

Command

Description

plt += plot(xs, ys)

This plots a series of (xs, ys) values. The xs and ys values must be collection-like objects (Breeze vectors, Scala arrays, or lists, for instance).

plt += scatter(xs, ys, size)

plt += scatter(xs, ys, size, color)

This plots a series of (xs, ys) values as a scatter plot. The size argument is an (Int) => Double function mapping the index of a point to its size (in the same units as the x axis). The color argument is an (Int) => java.awt.Paint function mapping from integers to colors. Read the more advanced scatter plots section for further details.

plt += hist(xs)

plt += hist(xs, bins=10)

This bins xs and plots a histogram. The bins argument controls the number of bins.

plt += image(mat)

This plots an image or matrix. The mat argument should be Matrix[Double]. Read the package.scala source file in breeze.plot for details (https://github.com/scalanlp/breeze/blob/master/viz/src/main/scala/breeze/plot/package.scala).

It is also useful to summarize the options available on a plot object:

Attribute

Description

plt.xlabel = "x-label"

plt.ylabel = "y-label"

This sets the axis label

plt.xlim = (0.0, 1.0)

plt.ylim = (0.0, 1.0)

This sets the axis maximum and minimum value

plt.logScaleX = true

plt.logScaleY = true

This switches the axis to a log scale

plt.title = "title"

This sets the plot title

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.217.220