Last active
May 8, 2023 20:34
-
-
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/d29b4b30c0d75a7d1a65311e762fc14844fca2e8
This file contains 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.2.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