Last active
May 25, 2024 10:18
-
-
Save dacr/3a59b0d98ef6e36dd70267cac3d29b59 to your computer and use it in GitHub Desktop.
Playing time series with plotly through plotly-scala. / published by https://github.com/dacr/code-examples-manager #450b643c-1a87-46b7-922b-3753e90b6c8f/8b6429834f25f71b41fb387bb8252171be838c2c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// summary : Playing time series with plotly through plotly-scala. | |
// keywords : scala, chart, plotly, timeseries | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : 450b643c-1a87-46b7-922b-3753e90b6c8f | |
// created-on : 2020-05-31T19:54:52Z | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
// --------------------- | |
//> using scala "3.4.2" | |
//> using dep "org.plotly-scala:plotly-render_2.13:0.8.4" | |
// --------------------- | |
// -- https://github.com/alexarchambault/plotly-scala | |
import plotly._, element._, layout._, Plotly._ | |
val rand = new java.util.Random() | |
val xs1 = (0 until 500) | |
val ys1 = xs1.map { i => i + 60.0 * rand.nextDouble() } | |
val xs2 = (0 until 500) | |
val ys2 = xs2.map { i => 500 - i + 60.0 * rand.nextDouble() } | |
val data = Seq( | |
Scatter(xs1, ys1).withName("trendAA"), | |
Scatter(xs2, ys2).withName("trendBB"), | |
).map(_.withFill(Fill.ToNextY).withStackgroup("A")) | |
val myLayout = | |
Layout() | |
.withTitle("MyTimeSeries") | |
plot("plot.html", data, myLayout) | |
println("It should even open the default browser with that chart !") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment