diff --git a/_posts/scala/surface-subplots/2016-06-19-3d_surface_plots.html b/_posts/scala/surface-subplots/2016-06-19-3d_surface_plots.html new file mode 100644 index 000000000000..7df7f983fdeb --- /dev/null +++ b/_posts/scala/surface-subplots/2016-06-19-3d_surface_plots.html @@ -0,0 +1,15 @@ +--- +title: 3D Subplots | Examples | Plotly +name: 3D Subplots +permalink: scala/3d-subplots/ +description: How to create subplots with 3D graphs in Scala +layout: base +thumbnail: thumbnail/3d-subplots.jpg +language: scala +page_type: example_index +has_thumbnail: true +display_as: 3d_charts +order: 5 +--- +{% assign examples = site.posts | where:"language","scala" | where:"suite","3d-subplots" | sort: "order" %} +{% include auto_examples.html examples=examples %} diff --git a/_posts/scala/surface-subplots/2016-06-19-surface-subplots.html b/_posts/scala/surface-subplots/2016-06-19-surface-subplots.html new file mode 100644 index 000000000000..90fe03cdd95c --- /dev/null +++ b/_posts/scala/surface-subplots/2016-06-19-surface-subplots.html @@ -0,0 +1,46 @@ +--- +name: 3D surface subplots +plot_url: https://plot.ly/~pbugnion/546 +language: scala +suite: 3d-subplots +order: 2 +sitemap: false +arrangement: horizontal +--- + +val xs = (-3.0 to 3.0 by 0.2).toVector +val ys = (-3.0 to 3.0 by 0.2).toVector + +// 2-dimensional quantum harmonic oscillator energy levels +def gaussian2D(x: Double, y: Double): Double = Math.exp(-x*x - y*y) +val z00 = xs.map { x => ys.map { y => gaussian2D(x, y) } } +val z01 = xs.map { x => ys.map { y => y*gaussian2D(x, y) } } +val z11 = xs.map { x => ys.map { y => x*y*gaussian2D(x, y) } } +val z20 = xs.map { x => ys.map { y => (1-2*x*x)*gaussian2D(x, y) } } + +val options = SurfaceOptions().noScale + +val figure = GridFigure(2, 2) // four plots split over two rows + .title("Eigenfunctions of the 2D quantum harmonic oscillator") + .plot(0, 0) { // top left + ThreeDPlot() + .withSurface(xs, ys, z00, options) + .zAxisOptions(AxisOptions().title("psi_00")) + } + .plot(0, 1) { // top right + ThreeDPlot() + .withSurface(xs, ys, z01, options) + .zAxisOptions(AxisOptions().title("psi_01")) + } + .plot(1, 0) { // bottom left + ThreeDPlot() + .withSurface(xs, ys, z11, options) + .zAxisOptions(AxisOptions().title("psi_11")) + } + .plot(1, 1) { // bottom right + ThreeDPlot() + .withSurface(xs, ys, z20, options) + .zAxisOptions(AxisOptions().title("psi_20")) + } + +draw(figure, "qho-eigenfunctions") diff --git a/_posts/scala/surface/2016-06-19-3d-surface-plot.html b/_posts/scala/surface/2016-06-19-3d-surface-plot.html new file mode 100644 index 000000000000..08d1cb5bb4a4 --- /dev/null +++ b/_posts/scala/surface/2016-06-19-3d-surface-plot.html @@ -0,0 +1,19 @@ +--- +name: 3D surface plot +plot_url: https://plot.ly/~pbugnion/518 +language: scala +suite: surface +order: 1 +sitemap: false +arrangement: horizontal +--- + +val xs = (-3.0 to 3.0 by 0.1).toVector +val ys = (-3.0 to 3.0 by 0.1).toVector + +def gaussian2D(x: Double, y: Double) = Math.exp(-x*x - y*y) +val zs = xs.map { x => ys.map { y => gaussian2D(x, y) } } + +val p = ThreeDPlot().withSurface(xs, ys, zs) + +draw(p, "gaussian-surfaces") diff --git a/_posts/scala/surface/2016-06-19-3d_surface_plots.html b/_posts/scala/surface/2016-06-19-3d_surface_plots.html new file mode 100644 index 000000000000..1b03a2ce7aab --- /dev/null +++ b/_posts/scala/surface/2016-06-19-3d_surface_plots.html @@ -0,0 +1,15 @@ +--- +title: 3D Surface plots | Examples | Plotly +name: 3D Surface plots +permalink: scala/3d-surface-plots/ +description: How to create surface plots in Plotly with Scala. +layout: user-guide +thumbnail: thumbnail/3d-surface.jpg +language: scala +page_type: example_index +has_thumbnail: true +display_as: 3d_charts +order: 4 +--- +{% assign examples = site.posts | where:"language","scala" | where:"suite","surface" | sort: "order" %} +{% include auto_examples.html examples=examples %} diff --git a/_posts/scala/surface/2016-06-19-multiple-surfaces.html b/_posts/scala/surface/2016-06-19-multiple-surfaces.html new file mode 100644 index 000000000000..975f92f002b3 --- /dev/null +++ b/_posts/scala/surface/2016-06-19-multiple-surfaces.html @@ -0,0 +1,38 @@ +--- +name: Multiple surface plots +plot_url: https://plot.ly/~pbugnion/520 +language: scala +suite: surface +order: 3 +sitemap: false +arrangement: horizontal +--- + +// z data +val z1 = Vector( + Vector(8.83, 8.89, 8.81, 8.87, 8.9, 8.87), + Vector(8.89, 8.94, 8.85, 8.94, 8.96, 8.92), + Vector(8.84, 8.9, 8.82, 8.92, 8.93, 8.91), + Vector(8.79, 8.85, 8.79, 8.9, 8.94, 8.92), + Vector(8.79, 8.88, 8.81, 8.9, 8.95, 8.92), + Vector(8.8, 8.82, 8.78, 8.91, 8.94, 8.92), + Vector(8.75, 8.78, 8.77, 8.91, 8.95, 8.92), + Vector(8.8, 8.8, 8.77, 8.91, 8.95, 8.94), + Vector(8.74, 8.81, 8.76, 8.93, 8.98, 8.99), + Vector(8.89, 8.99, 8.92, 9.1, 9.13, 9.11), + Vector(8.97, 8.97, 8.91, 9.09, 9.11, 9.11), + Vector(9.04, 9.08, 9.05, 9.25, 9.28, 9.27), + Vector(9, 9.01, 9, 9.2, 9.23, 9.2), + Vector(8.99, 8.99, 8.98, 9.18, 9.2, 9.19), + Vector(8.93, 8.97, 8.97, 9.18, 9.2, 9.18) +) + +val z2 = z1.map { _.map { _ + 1.0 } } +val z3 = z1.map { _.map { _ - 1.0 } } + +val p = ThreeDPlot() + .withSurface(z1) + .withSurface(z2, SurfaceOptions().opacity(0.9).noScale) + .withSurface(z3, SurfaceOptions().opacity(0.9).noScale) + +draw(p, "multiple-surfaces") diff --git a/_posts/scala/surface/2016-06-19-styled-surface-plot.html b/_posts/scala/surface/2016-06-19-styled-surface-plot.html new file mode 100644 index 000000000000..9a9a1ba8ea6c --- /dev/null +++ b/_posts/scala/surface/2016-06-19-styled-surface-plot.html @@ -0,0 +1,48 @@ +--- +name: Styled surface plot +plot_url: https://plot.ly/~pbugnion/532 +language: scala +suite: surface +order: 2 +sitemap: false +arrangement: horizontal +--- + +/* +This example requires the `csv` package. To include it, add the +following lines to your `build.sbt file + +libraryDependencies += "com.github.tototoshi" %% "scala-csv" % "1.3.1" +*/ + +import scala.io.Source +import com.github.tototoshi.csv._ +import co.theasi.plotly._ + +object MountBruno extends App { + + val dataURL = "https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv" + val reader = CSVReader.open(Source.fromURL(dataURL)) + + val firstRow :: dataRows = reader.all + + val data = dataRows.map { + case index :: values => values + case _ => throw new IllegalStateException("Empty file") + } + + val axisOptions = AxisOptions().noGrid.noLine.noZeroLine.noTickLabels.title("") + + val p = ThreeDPlot() + .withSurface(data, SurfaceOptions().colorscale("Earth").noScale) + .xAxisOptions(axisOptions) + .yAxisOptions(axisOptions) + .zAxisOptions(axisOptions) + + val figure = Figure() + .plot(p) + .margins(0, 0, 0, 0) + + val outputFile = draw(figure, "Mt Bruno") + println(outputFile) +}