kandy 0.6.0 Help

Kotlin Notebook Features

This notebook demonstrates the features available when working with kandy-lets-plot in Kotlin Notebook

Swing render

By default, Kotlin Notebook uses Swing to display plots:

val rand = Random(42) val simpleData = dataFrameOf( "time" to (1..10).toList(), "value" to List(10) { rand.nextDouble(0.0, 1.0) }, "type" to (List(5) { "a" } + List(5) { "b" }).shuffled(rand), "active" to List(10) { rand.nextBoolean() }, )
val plot = simpleData.plot { points { x(time) y(value) color(type) size = 6.0 tooltips(type, active) } } plot
Guide ktnb features default swing

Swing rendering has a lot of advantages: it is more performant (when using tooltips), you can change its size (in this case it will be scaled), and also has a dynamically changing color scheme (see the relevant section).

However, you can disable it manually and use web rendering (may not work at all in Kotlin Notebook — try to restart kernel). To do this, before displaying the plot, it is necessary to change the corresponding option in kandyConfig (notebook parameter).

kandyConfig.swingEnabled = false
plot
Guide ktnb features swing false

Dynamic color scheme

If you are using a non-light color scheme in the editor, you may have noticed that the swing-rendered plot has automatically changed its theme to match the environment theme. If not already, you can check this by changing the theme of your editor to, for example, Darcula. Even without restarting the cell, the next plot (just like the first swing plot) will change the theme to match yours.

// Switching the swing rendering back on kandyConfig.swingEnabled = true
plot
Guide ktnb features swing true

To disable the automatic theme change, you need to change the corresponding flag in kandyConfig:

kandyConfig.applyColorScheme = false
plot
Guide ktnb features color schema

Also note that automatic theme change does not work if you set the theme manually (via layout.flavor):

kandyConfig.applyColorScheme = true
simpleData.plot { points { x(time) y(value) color(type) size = 6.0 tooltips(type, active) } layout.theme = Theme.HIGH_CONTRAST_DARK }
Guide ktnb features high contrast

Plot Export from Output

You can export plot from the cell output with the "Export Plot As..." button in the output menu or with "Export Plot As..." action.

Plot Export Button

After that, a settings menu will open where you can select the image format, the path to where you want to save it, as well as the file name itself.

Plot Export Button
Last modified: 13 May 2024