Skip to content

Temperature Heatmap ​

The highest daily maximum temperature in Seattle for each day of the year, over four years. cm.group reduces the days on x and y, and cm.inset insets the touching cells by 0.5px. After Observable Plot.

js
const seattle = await d3.csv("/data/seattle-weather.csv", d3.autoType);
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

const renderer = cm.svg({width: 640, height: 300});
const root = cm.flow().renderer(renderer);

root
  .data(seattle)
  .transform(cm.encode, {
    x: (d) => d.date.getUTCDate(),
    y: (d) => d.date.getUTCMonth(),
    fill: "temp_max",
  })
  .transform(cm.group, {fill: "max"})
  .transform(cm.spreadX, {padding: 0})
  .transform(cm.spreadY, {padding: 0})
  .transform(cm.plane, {y: {tickFormat: (d) => months[d]}})
  .add(cm.rect, cm.inset(0.5));

root.render();
document.body.append(renderer.node());