Skip to content

Omitting years for automatically formatted date axis labels impedes interpretation of axis  #9747

@juanmpga

Description

@juanmpga

What happened?

Image

As you can see, the x tick labels on the plot show months but no year references.

Code to reproduce:

import numpy as np
import polars as pl
import altair as alt
from datetime import datetime, timedelta

start_date = datetime(2015, 9, 10)
num_days = 3695
dates = pl.date_range(
    start=start_date,
    end=start_date + timedelta(days=num_days - 1),
    interval="1d",
    eager=True,
)
price = np.ones(num_days)

df = pl.DataFrame({
    "Date": dates,
    "Data": price,
})

(
    alt.Chart(df.select(["Date", "Data"]))
    .mark_line(opacity=0.5)
    .encode(x="Date", y="Data")
    .properties(height=200, width=900)
)

What would you like to happen instead?

I can think of several options:

  1. Display years slightly below months
  2. Display years in between months
  3. Display years in place of months

Any would work for me. 3. implies losing some granularity but maybe is simpler. Generally I think the most important value to show is the lowest frequency period that changes within the plotting window, but I haven't thought this through thoroughly.

Which version of Altair are you using?

6.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Enhancement.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions