How to add months between years?

This is my observable plot:

I want to add months between years, but I don’t know how to do it.

1 Like

I guess you’re using Observable Plot? Personally, I think it’s generally best to let Plot pick the tick placements for you. Note that months will appear for the date range you’ve got, if your plot is wide enough. You can see that effect by fiddling with the slider below.

You can specify tick placement quite precisely, if desired, though. You might also want to specify the tick format to be something relatively compact:

You can view the code for both of those in this notebook. The key portion that specifies the ticks on the horizontal axis is this:

x: {
  domain: [d3.utcParse("%Y")(2017), d3.utcParse("%Y")(2023)],
  // Specify a tick to appear every 6 months
  ticks: d3.timeMonth.range(
    d3.utcParse("%Y")("2017"),
    d3.utcParse("%Y")("2024"),
    6
  ),
  // Specify a compact format for the ticks
  tickFormat: d3.timeFormat("%b/%y")
},
2 Likes