I would like to write a completely minimal example of lets-plot, which just saves png and doesn't use any frontend. For this, I created a "helloworld" Kotlin project in IntelliJ IDEA. Then I added Maven dependency org.jetbrains.lets-plot:lets-plot-common:2.1.0. Now if I try to import jetbrains.letsPlot.letsPlot, I get the error "Unresolved reference: letsPlot". Thus, the question is how to write the most minimal lets-plot example, without using any frontend and Gradle.
Asked
Active
Viewed 1,029 times
1
-
What is more minimal about using Maven instead of Gradle? – Markus Weninger Sep 05 '21 at 22:14
-
Check the lets-plot project examples for JVM, see this project README section: https://github.com/JetBrains/lets-plot-kotlin#lets-plot-in-jvm-and-kotlinjs-application – Andrey Sep 06 '21 at 08:13
1 Answers
2
The right dependencies are org.jetbrains.lets-plot:lets-plot-kotlin-jvm:3.0.2 (for API) and org.jetbrains.lets-plot:lets-plot-image-export:2.1.0 (to be able to export to raster). Now it works, and the resulting image in lets-plot-images directory.
The code:
import jetbrains.letsPlot.export.ggsave
import jetbrains.letsPlot.geom.geomPoint
import jetbrains.letsPlot.letsPlot
fun main() {
val xs = listOf(0, 0.5, 1, 2)
val ys = listOf(0, 0.25, 1, 4)
val data = mapOf<String, Any>("x" to xs, "y" to ys)
val fig = letsPlot(data) + geomPoint(
color = "dark-green",
size = 4.0
) { x = "x"; y = "y" }
ggsave(fig, "plot.png")
}

E. Nerush
- 69
- 7