Skip to content

Commit ec63aca

Browse files
authored
Upgraded the lets-plot library and Kotlin API to the 4.x version and migrated the API (#569)
* Update Lets-Plot library and adjust import paths Updated the Lets-Plot library in build.gradle from version 2.3.0 to 4.0.1 and 2.0.1 to 4.4.3. * Refined comments and modified code for clarity Refactored code for better readability. Corrected grammar and improved sentence structure in comments for better understanding. Also, tweaked theme configuration in 'PlotDefinition.kt' for explicit settings. Updated example comment on 'SoundNetFSDDVisualization.kt' to be singular as it demonstrates a single example.
1 parent adc07f4 commit ec63aca

File tree

5 files changed

+32
-28
lines changed

5 files changed

+32
-28
lines changed

examples/src/main/kotlin/examples/visualization/SoundNetFSDDVisualization.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ private const val TEST_BATCH_SIZE = 512
3333

3434

3535
/**
36-
* This examples demonstrates model activations and Conv1D filters visualization.
36+
* This example demonstrates model activations and Conv1D filters visualization.
3737
* Additionally, we present the visualization of sound files as the plots of the sound data.
3838
*
3939
* Model is trained on Free Spoken Digits Dataset.
4040
*/
4141
fun main() {
42-
4342
visualizeFSDDWavFiles()
4443

4544
val (train, test) = freeSpokenDigits()

visualization/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ kotlin {
2020

2121
def excludeSLF4JImpl = { exclude group: 'org.slf4j', module: 'slf4j-simple' }
2222

23-
api 'org.jetbrains.lets-plot:lets-plot-batik:2.3.0', excludeSLF4JImpl
24-
api 'org.jetbrains.lets-plot:lets-plot-common:2.3.0', excludeSLF4JImpl
25-
api 'org.jetbrains.lets-plot:lets-plot-kotlin-api:2.0.1', excludeSLF4JImpl
23+
api 'org.jetbrains.lets-plot:lets-plot-batik:4.0.1', excludeSLF4JImpl
24+
api 'org.jetbrains.lets-plot:lets-plot-common:4.0.1', excludeSLF4JImpl
25+
api 'org.jetbrains.lets-plot:lets-plot-kotlin-jvm:4.4.3', excludeSLF4JImpl
2626
}
2727
}
2828
androidMain {

visualization/src/jvmMain/kotlin/org/jetbrains/kotlinx/dl/visualization/letsplot/PlotConv2D.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
package org.jetbrains.kotlinx.dl.visualization.letsplot
77

8-
import jetbrains.letsPlot.Figure
98
import org.jetbrains.kotlinx.dl.api.core.FloatData
109
import org.jetbrains.kotlinx.dl.api.core.TrainableModel
1110
import org.jetbrains.kotlinx.dl.api.core.layer.convolutional.Conv2D
1211
import org.jetbrains.kotlinx.dl.api.core.layer.weights
12+
import org.jetbrains.letsPlot.Figure
1313

1414
internal val FILTER_LAYERS_PERMUTATION = intArrayOf(1, 0, 2, 3)
1515

visualization/src/jvmMain/kotlin/org/jetbrains/kotlinx/dl/visualization/letsplot/PlotDefinition.kt

+11-8
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
package org.jetbrains.kotlinx.dl.visualization.letsplot
77

8-
import jetbrains.letsPlot.geom.geomRaster
9-
import jetbrains.letsPlot.intern.Scale
10-
import jetbrains.letsPlot.scale.scaleFillGrey
11-
import jetbrains.letsPlot.scale.scaleFillHue
12-
import jetbrains.letsPlot.theme
8+
import org.jetbrains.letsPlot.geom.geomRaster
9+
import org.jetbrains.letsPlot.intern.Scale
10+
import org.jetbrains.letsPlot.scale.scaleFillGrey
11+
import org.jetbrains.letsPlot.scale.scaleFillHue
12+
import org.jetbrains.letsPlot.themes.theme
1313

1414
/**
1515
* PlotFeature represents the filling options for plots that defines its color scale.
@@ -30,6 +30,9 @@ class PlotFeature(val scale: Scale) {
3030

3131
internal val FEATURE_MAP_THEME =
3232
geomRaster(showLegend = false) +
33-
theme().axisTitleBlank()
34-
.axisTextBlank()
35-
.axisTicksBlank()
33+
theme(
34+
axisTitle = "blank",
35+
axisText = "blank",
36+
axisTicks = "blank"
37+
)
38+

visualization/src/jvmMain/kotlin/org/jetbrains/kotlinx/dl/visualization/letsplot/PlotGeneric.kt

+16-14
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
package org.jetbrains.kotlinx.dl.visualization.letsplot
77

8-
import jetbrains.letsPlot.Figure
9-
import jetbrains.letsPlot.geom.geomPath
10-
import jetbrains.letsPlot.gggrid
11-
import jetbrains.letsPlot.intern.Plot
12-
import jetbrains.letsPlot.label.ggtitle
13-
import jetbrains.letsPlot.letsPlot
8+
import org.jetbrains.letsPlot.Figure
9+
import org.jetbrains.letsPlot.geom.geomPath
10+
import org.jetbrains.letsPlot.gggrid
11+
import org.jetbrains.letsPlot.intern.Plot
12+
import org.jetbrains.letsPlot.label.ggtitle
13+
import org.jetbrains.letsPlot.letsPlot
1414
import org.jetbrains.kotlinx.dl.api.core.FloatData
1515
import org.jetbrains.kotlinx.dl.api.core.floats
1616
import org.jetbrains.kotlinx.dl.dataset.Dataset
@@ -19,16 +19,16 @@ import kotlin.math.max
1919
import kotlin.math.roundToInt
2020

2121
/**
22-
* Column plot arranges the given iterable of plots in specified number of columns and
22+
* Column plot arranges the given iterable of plots in a specified number of columns and
2323
* creates a single figure from all given plots
2424
*
25-
* @param plots that are arranged into single figure
25+
* @param plots these are arranged into a single figure
2626
* @param columns specifies the number of columns in which the plots are arranged
27-
* @param imageSize is a height and width of the single plot in returned plots figure
27+
* @param imageSize is a height and width of the single plot in a returned plots figure
2828
* @return a [Figure] with all given plots
2929
*/
3030
fun columnPlot(plots: Iterable<Plot>, columns: Int, imageSize: Int): Figure =
31-
gggrid(plots, columns, imageSize, imageSize, fit = true)
31+
gggrid(plots, columns)
3232

3333
/**
3434
* Create a tile plot with weights from specified function `f(x, y)` that specifies the
@@ -66,8 +66,10 @@ fun xyPlot(imageSize: Int, plotFeature: PlotFeature, f: (Int, Int) -> Float): Pl
6666
xyPlot(imageSize, imageSize, plotFeature, f)
6767

6868
/**
69-
* Create a [xyPlot] for image data given as array of the following intensities of the
70-
* plot tiles. Function intended to use with the inputs images from some [Dataset] for
69+
* Create a [xyPlot] for image data given as an array of the following intensities of the
70+
* plot tiles.
71+
*
72+
* Function intended to use it with the input images from some [Dataset] for
7173
* model as it offers to plot extra label that the specified image is labeled by (and
7274
* additionally supports plotting some predicted label when model prediction is given)
7375
*
@@ -105,8 +107,8 @@ fun flattenImagePlot(
105107
* cut from the beginning or its end because there may be extra noises that disturbs visualization.
106108
*
107109
* @param wavFile to read sound data from
108-
* @param beginDrop part of data to drop from begin from range [0, 1]
109-
* @param endDrop part of data to drop from end from range [0, 1]
110+
* @param beginDrop part of data to drop from beginning from range [0, 1]
111+
* @param endDrop part of data to drop from an end from range [0, 1]
110112
* @return [Plot] representing the amplitude of sound of given [WavFile]
111113
*/
112114
fun soundPlot(

0 commit comments

Comments
 (0)