Last active
May 25, 2024 10:19
-
-
Save dacr/57fc50e4da7fa7d83a0db7be69747a93 to your computer and use it in GitHub Desktop.
Playing with plotly through plotly-scala - multiplots / published by https://github.com/dacr/code-examples-manager #5e581dc7-4a72-44bd-8a7e-806dedd42d18/57a8d5a62c0ae53f3ea1e7eda8a493496248a44f
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 with plotly through plotly-scala - multiplots | |
// keywords : scala, chart, plotly, multiplots | |
// 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 : 5e581dc7-4a72-44bd-8a7e-806dedd42d18 | |
// created-on : 2021-03-06T21:44:28Z | |
// 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" | |
// --------------------- | |
import plotly._, element._, layout._, Plotly._ | |
// Inspired from https://zwild.github.io/posts/plotly-examples-for-scala/ | |
val data = Seq(1, 2) | |
val trace1 = { | |
Scatter(data, data) | |
.withName("(1,1)") | |
} | |
val trace2 = { | |
Scatter(data, data) | |
.withName("(1,2)") | |
.withXaxis(AxisReference.X2) | |
.withYaxis(AxisReference.Y2) | |
} | |
val trace3 = { | |
Scatter(data, data) | |
.withName("(1,3)") | |
.withXaxis(AxisReference.X3) | |
.withYaxis(AxisReference.Y3) | |
} | |
val trace4 = { | |
Scatter(data,data) | |
.withName("(1,4)") | |
.withXaxis(AxisReference.X4) | |
.withYaxis(AxisReference.Y4) | |
} | |
val useLayout = { | |
Layout() | |
.withTitle("Multiple Custom Sized Subplots") | |
.withXaxis( | |
Axis() | |
.withAnchor(AxisAnchor.Reference(AxisReference.Y1)) | |
.withDomain(Range.fromDoubleTuple(0, 0.45))) | |
.withYaxis( | |
Axis() | |
.withAnchor(AxisAnchor.Reference(AxisReference.X1)) | |
.withDomain(Range.fromDoubleTuple(0.5, 1))) | |
.withXaxis2( | |
Axis() | |
.withAnchor(AxisAnchor.Reference(AxisReference.Y2)) | |
.withDomain(Range.fromDoubleTuple(0.55, 1))) | |
.withYaxis2( | |
Axis() | |
.withAnchor(AxisAnchor.Reference(AxisReference.X2)) | |
.withDomain(Range.fromDoubleTuple(0.8, 1))) | |
.withXaxis3( | |
Axis() | |
.withAnchor(AxisAnchor.Reference(AxisReference.Y3)) | |
.withDomain(Range.fromDoubleTuple(0.55, 1))) | |
.withYaxis3( | |
Axis() | |
.withAnchor(AxisAnchor.Reference(AxisReference.X3)) | |
.withDomain(Range.fromDoubleTuple(0.5, 0.75))) | |
.withXaxis4( | |
Axis() | |
.withAnchor(AxisAnchor.Reference(AxisReference.Y4)) | |
.withDomain(Range.fromDoubleTuple(0, 1))) | |
.withYaxis4( | |
Axis() | |
.withAnchor(AxisAnchor.Reference(AxisReference.X4)) | |
.withDomain(Range.fromDoubleTuple(0, 0.45))) | |
} | |
Seq(trace1, trace2, trace3, trace4).plot( | |
"subplots.html", | |
useLayout, | |
false, | |
true, | |
true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment