kandy 0.7.0 Help

Plot Bunch

plotBunch() allows showing a collection of plots on one figure. Each plot in the collection can have an arbitrary location and size. There is no automatic layout inside the bunch.

val cov: Array<DoubleArray> = arrayOf( doubleArrayOf(1.0, 0.0), doubleArrayOf(0.0, 1.0) ) val means: DoubleArray = doubleArrayOf(0.0, 0.0) val random = JDKRandomGenerator(42) val xy = MultivariateNormalDistribution(random, means, cov).sample(400) val xs = xy.map { it[0] } val ys = xy.map { it[1] }

View this data as a scatter plot and as a histogram

plot { points { x(xs) y(ys) color = Color.GREY alpha = .4 } layout { size = 600 to 200 xAxisLabel = "x" yAxisLabel = "y" } }
Scatter Plot
plot { histogram(xs) { fillColor = Color.named("dark_magenta") } layout { size = 600 to 200 xAxisLabel = "x" } }
Histogram Plot

Combine both plots in one figure

val scaleX = Scale.continuousPos(-3.5..3.5) plotBunch { add(plot { histogram(xs) { x { scale = scaleX } fillColor = Color.named("dark_magenta") } layout { size = 600 to 200 xAxisLabel = "x" } }, 0, 0) add(plot { points { x(xs) { scale = scaleX } y(ys) color = Color.GREY alpha = .4 } layout { size = 600 to 200 xAxisLabel = "x" yAxisLabel = "y" } }, 0, 200) }
Combine Scatter and Histogram

Adjust visuals of the bunch figure

val upperStyle = Style.createCustom { blankAxes() axis.text { } yAxis.title { } panel.grid.majorYLine { blank = true } } val lowerStyle = Style.createCustom { blankAxes() yAxis.text { } axis.title { } }
plotBunch { add(plot { histogram(xs) { x { scale = scaleX } fillColor = Color.named("dark_magenta") } layout { size = 600 to 200 xAxisLabel = "x" style(upperStyle) } }, 0, 0) add(plot { points { x(xs) { scale = scaleX } y(ys) color = Color.GREY alpha = .4 } layout { size = 600 to 200 xAxisLabel = "x" yAxisLabel = "y" style(lowerStyle) } }, 0, 200) }
Plot Bunch with Styles

Adjust plot sizes

add method has two more (optional) parameters: width and height.

These values will override the plot size earlier defined via size property.

plotBunch { add(plot { histogram(xs) { x { scale = scaleX } fillColor = Color.named("dark_magenta") } layout { size = 600 to 200 xAxisLabel = "x" style(upperStyle) } }, 0, 0, 600, 100) add(plot { points { x(xs) { scale = scaleX } y(ys) color = Color.GREY alpha = .4 } layout { size = 600 to 200 xAxisLabel = "x" yAxisLabel = "y" style(lowerStyle) } }, 0, 100, 600, 300) }
Configured Sizes
Last modified: 29 February 2024