Skip to content

Simpsons Ratings ​

The IMDb rating of each Simpsons episode by season, in cells colored with PiYG and labeled with their ratings. cm.spreadX and cm.spreadY make the bands, and cm.label centers the ratings in the cells. Episodes without a rating are left out. After Observable Plot.

js
const simpsons = (await d3.csv("/data/simpsons.csv", d3.autoType)).filter((d) => d.imdb_rating != null);

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

root
  .data(simpsons)
  .transform(cm.encode, {
    x: "season",
    y: "number_in_season",
    fill: "imdb_rating",
  })
  .transform(cm.spreadX, {padding: 0})
  .transform(cm.spreadY, {padding: 0})
  .transform(cm.plane, {
    marginBottom: 10,
    x: {axis: "top", label: "Season", grid: true},
    y: {label: "Episode", grid: true},
    fill: {type: "linear", scheme: "PiYG", label: "IMDb rating", legend: true},
  })
  .add(cm.rect, cm.inset(0.5))
  .add(cm.label, {text: (d) => d.datum.imdb_rating.toFixed(1), fill: "black"});

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