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]:
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]: