Last active
May 25, 2024 10:19
-
-
Save dacr/cf7fce263d43766d356326ada71760f6 to your computer and use it in GitHub Desktop.
Playing time series and multiple Y axis with plotly through plotly-scala. / published by https://github.com/dacr/code-examples-manager #0c4db2ab-5344-438b-9158-0a4223253404/fff7a052c427ee94798c7d71cdbeaaa70705f878
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 and multiple Y axis 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 : 0c4db2ab-5344-438b-9158-0a4223253404 | |
// 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 + 200.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").withYaxis(AxisReference.Y2), | |
).map(_.withFill(Fill.ToNextY).withStackgroup("A")) | |
val myLayout = | |
Layout() | |
.withTitle("MyTimeSeries") | |
.withYaxis( | |
Axis() | |
.withTitle("A") | |
) | |
.withYaxis2( | |
Axis() | |
.withOverlaying(AxisAnchor.Y) | |
.withSide(Side.Right) | |
) | |
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