Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active May 8, 2023 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacr/57fc50e4da7fa7d83a0db7be69747a93 to your computer and use it in GitHub Desktop.
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/f4c28c866afdb2a5e817b72cd06ce6f9e77cb4da
// 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.2.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