JetBrains / lets-plot-kotlin

Grammar of Graphics for Kotlin
https://lets-plot.org/kotlin/
MIT License
419 stars 36 forks source link

ggsave: saving `geomImshow()` to SVG produces fuzzy picture #188

Closed alshan closed 10 months ago

alshan commented 1 year ago

Try ggsave the last plot in image_101.ipynb to svg :

image

Saving to HTML is fine.

alshan commented 1 year ago

Same issue in Python LP.

alshan commented 1 year ago

In prev. LP v3.1.0 (py) saving imshow to SVG worked producing sharp images.

IKupriyanov-HORIS commented 1 year ago

Test notebook:

%use lets-plot
%use lib-ext

LetsPlot.getInfo()

//%

import java.awt.image.*
import javax.imageio.*
import java.nio.file.*

fun display(path: String): Any {
    if (path.endsWith("svg")) {
        val svg = Files.readString(Path.of(path))
        return HTML(svg)
    } else {
        val img = ImageIO.read(File(path))
        return Image(img)
    }
}

//%

val A2x3x4 = RasterData.create(
    listOf(
        listOf(
            listOf(1.0, 0.0, 0.0, 1.0), listOf(0.0, 1.0, 0.0, 1.0), listOf(0.0, 0.0, 1.0, 1.0)
        ),
        listOf(
            listOf(0.0, 1.0, 0.0, 0.3), listOf(0.0, 0.0, 1.0, 0.3), listOf(1.0, 0.0, 0.0, 0.3)
        )
    )
)

//%

val p = ggplot() + geomImshow(A2x3x4)
p.show()

//%

display(ggsave(p, "LPK-188.svg"))

//%

display(ggsave(p, "LPK-188.png"))
alshan commented 10 months ago

Fixed in 4.4.2