Kotlin:如何在IDEA中导入Lets Plot

mlmc2os5  于 2023-11-16  发布在  Kotlin
关注(0)|答案(1)|浏览(116)

我是Jetbrains IDEA编辑器的新手。我有一个控制台应用程序项目。我如何添加Let's Plot库/包/what-do-you-call-it,以便我可以绘制一些函数并将它们导出为SVG文件?
我发现这个问题很有帮助,但是它没有显示如何导入它,只显示如何使用它:Kotlin lets-plot: minimal example

tjrkku2a

tjrkku2a1#

在IntelliJ中:文件->新建项目-> Gradle + GradleDSL=Kotlin

Gradle - build.gradle.kts

plugins {
    kotlin("jvm") version "1.9.20"
}

group = "org.mygroup"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {

    implementation("org.jetbrains.lets-plot:lets-plot-kotlin-jvm:4.5.0")
    implementation("org.jetbrains.lets-plot:lets-plot-image-export:4.1.0")

    testImplementation(kotlin("test"))
}

tasks.test {
    useJUnitPlatform()
}

kotlin {
    jvmToolchain(17)
}

字符串

示例驱动程序

import org.jetbrains.letsPlot.export.ggsave
import org.jetbrains.letsPlot.geom.geomPoint
import org.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" }

    // save .svg file in the current dir
    ggsave(plot = fig, filename = "fig.svg", path = ".")
}

相关问题