System Colors¶

In [1]:
%useLatestDescriptors
%use dataframe
%use lets-plot
In [2]:
import org.jetbrains.letsPlot.intern.figure.SubPlotsFigure
import org.jetbrains.letsPlot.intern.Feature
In [3]:
fun docsDarkTheme(): Feature {
    val bgColor = "#19191c"
    return theme(
        plotBackground = elementRect(fill = bgColor),
        geom = elementGeom(pen = "white", paper = bgColor)
    ) + flavorHighContrastDark()
}
In [4]:
fun getSystemColorPlot(kind: String): SubPlotsFigure {
    val (w, h) = Pair(400.0, 300.0)
    val (th, lh) = Pair(50.0, 75.0)
    val width = w
    val height = h + th + lh
    val df = DataFrame.readCSV("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv")
    val titleColor = when (kind) {
        "paper" -> "pen"
        else -> "paper"
    }
    val titleLabelSize = when (kind) {
        "paper" -> null
        else -> 0
    }
    val pTitle = letsPlot() +
        geomLabel(x = 0, label = kind,
                  size = 10, labelSize = titleLabelSize, color = titleColor, fill = kind, family = "mono") +
        themeVoid()
    val (label, pExample) = when (kind) {
        "pen" -> Pair(
            "A hight-contrast color\ncommonly used to draw dots and lines",
            letsPlot(df.toMap()) { x = "cty"; y = "hwy" } + geomPoint()
        )
        "brush" -> Pair(
            "A color we often use to fill shapes",
            letsPlot(df.toMap()) { x = "fl" } + geomBar()
        )
        "paper" -> Pair(
            "A \"background\" color\nwe often use to fill shapes as well",
            letsPlot(df.toMap()) { x = "drv"; y = "cty" } + geomBoxplot()
        )
        else -> throw IllegalStateException()
    }
    val pLabel = letsPlot() +
        geomText(x = 0, label = label, size = 10) +
        themeVoid()
    return ggbunch(
        listOf(pTitle, pLabel, pExample),
        listOf(
            listOf(0, 0, w / width, th / height),
            listOf(0, th / height, w / width, lh / height),
            listOf(0, (th + lh) / height, w / width, h / height)
        )
    ) + ggsize(width, height)
}
In [5]:
val penPlot = getSystemColorPlot("pen")
ggsave(penPlot, "aesthetics_color_pen.png")
val brushPlot = getSystemColorPlot("brush")
ggsave(brushPlot, "aesthetics_color_brush.png")
val paperPlot = getSystemColorPlot("paper")
ggsave(paperPlot, "aesthetics_color_paper.png")
gggrid(listOf(penPlot, brushPlot, paperPlot)) + ggsize(1200, 500)
Out[5]:
pen A hight-contrast color commonly used to draw dots and lines 10 15 20 25 30 35 15 20 25 30 35 40 45 hwy cty brush A color we often use to fill shapes p r e d c 0 50 100 150 count fl paper A "background" color we often use to fill shapes as well f 4 r 10 15 20 25 30 35 cty drv
In [6]:
val penPlotDark = getSystemColorPlot("pen") + docsDarkTheme()
ggsave(penPlotDark, "aesthetics_color_pen_dark.png")
val brushPlotDark = getSystemColorPlot("brush") + docsDarkTheme()
ggsave(brushPlotDark, "aesthetics_color_brush_dark.png")
val paperPlotDark = getSystemColorPlot("paper") + docsDarkTheme()
ggsave(paperPlotDark, "aesthetics_color_paper_dark.png")
gggrid(listOf(penPlotDark, brushPlotDark, paperPlotDark)) + ggsize(1200, 500)
Out[6]:
pen A hight-contrast color commonly used to draw dots and lines 10 15 20 25 30 35 15 20 25 30 35 40 45 hwy cty brush A color we often use to fill shapes p r e d c 0 50 100 150 count fl paper A "background" color we often use to fill shapes as well f 4 r 10 15 20 25 30 35 cty drv