Color by Category
Color by Category
Use this when: You need to map a discrete category column onto point color via the categorical palette.
Usage
from dataviz import Plot, save
def main() raises:
var x: List[Float64] = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
var y: List[Float64] = [12.0, 9.0, 18.0, 15.0, 22.0, 20.0, 27.0, 25.0]
var region: List[String] = [
"North",
"South",
"North",
"South",
"North",
"South",
"North",
"South",
]
var plot = (
Plot()
.mark_point()
.encode(x=x, y=y, color_categories=region)
.labels(
title="Readings by Region",
subtitle="Color mapped to a discrete category",
)
)
save(plot, "docs/src/examples/out_color_categorical.svg")Related
Related recipes: Color by Continuous Variable