79123462

Date: 2024-10-24 20:06:36
Score: 0.5
Natty:
Report link

If you use the ordinal or nominal data type, you can supply a timeUnit to get date formatting. There are many options depending on what kind of data you are working with.

import altair as alt
import polars as pl

source = pl.DataFrame(
    {
        "Category": list("AAABBBCCC"),
        "Value": [0.1, 0.6, 0.9, 0.7, 0.2, 1.1, 0.6, 0.1, 0.2],
        "Date": [f"2024-{m+1}-1" for m in range(3)] * 3,
    }
).with_columns(pl.col("Date").str.to_date())

bars = alt.Chart(source.to_pandas()).mark_bar().encode(
    x=alt.X("Date:O", timeUnit="yearmonthdate"),
    xOffset="Category:N",
    y="Value:Q",
    color="Category:N",
)

bars

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: kgoodrick