Line Types¶
In [1]:
%useLatestDescriptors
%use lets-plot
In [2]:
import org.jetbrains.letsPlot.intern.Plot
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()
}
Predefined Patterns¶
In [4]:
fun getPredefinedLinetypePlot(): Plot {
val linetypeNames = listOf("blank", "solid", "dashed", "dotted", "dotdash", "longdash", "twodash")
val linetypeIds = (0 until linetypeNames.size).toList()
return letsPlot() +
geomSpoke(x = 0, angle = 0, radius = 1, size = 4, color = "#fa9fb5", alpha = 0.25) { y = linetypeIds } +
geomSpoke(x = 0, angle = 0, radius = 1, size = 2, showLegend = false) { y = linetypeIds; linetype = linetypeIds } +
geomLabel(x = 0, hjust = 0, size = 12, labelSize = 0, labelFormat = "{d}:", position = positionNudge(y = 0.3), family = "mono")
{ y = linetypeIds; label = linetypeIds } +
geomLabel(x = 0.04, hjust = 0, size = 12, labelSize = 0, labelFormat = "'{}'", position = positionNudge(y = 0.3), family = "mono")
{ y = linetypeIds; label = linetypeNames } +
scaleYReverse() +
scaleLinetypeIdentity() +
coordCartesian(xlim = Pair(0, 1), ylim = Pair(-0.5, linetypeNames.size - 0.75)) +
ggsize(800, 600) +
themeVoid()
}
In [5]:
val plPlot = getPredefinedLinetypePlot()
ggsave(plPlot, "aesthetics_linetype.png")
plPlot
Out[5]:
In [6]:
val plPlotDark = getPredefinedLinetypePlot() + docsDarkTheme()
ggsave(plPlotDark, "aesthetics_linetype_dark.png")
plPlotDark
Out[6]:
Custom Patterns¶
In [7]:
fun getCustomLinetypePlot(): Plot {
val linetypePatterns = listOf(
listOf(10, 6),
listOf(8, listOf(10, 6)),
"A636",
)
val linetypePatternNames = linetypePatterns.map { it.toString() }
val linetypeIds = (0 until linetypePatterns.size).toList()
return letsPlot() +
geomSpoke(x = 0, angle = 0, radius = 1, size = 4, color = "#fa9fb5", alpha = 0.25)
{ y = linetypeIds } +
geomSpoke(x = 0, angle = 0, radius = 1, size = 2, showLegend = false)
{ y = linetypeIds; linetype = linetypePatterns } +
geomLabel(x = 0, hjust = 0, size = 12, labelSize = 0, labelFormat = "{}", position = positionNudge(y = 0.3), family = "mono")
{ y = linetypeIds; label = linetypePatternNames } +
scaleYReverse() +
scaleLinetypeIdentity() +
coordCartesian(xlim = Pair(0, 1), ylim = Pair(-0.5, linetypePatterns.size - 0.75)) +
ggsize(800, 300) +
themeVoid()
}
In [8]:
val clPlot = getCustomLinetypePlot()
ggsave(clPlot, "aesthetics_custom_linetype.png")
clPlot
Out[8]:
In [9]:
val clPlotDark = getCustomLinetypePlot() + docsDarkTheme()
ggsave(clPlotDark, "aesthetics_custom_linetype_dark.png")
clPlotDark
Out[9]: