Plot.contour

There is an excellent notebook on using Plot.contour() at Contour Mark / Observable Plot / Observable | Observable but it is mostly for plotting contours of densities. I want to plot a contour for a function. The last example in that notebook illustrates plotting contours for function but using facets. I’m having trouble sorting out which parts of the code are for the facets and which for the function. Unfortunately, the API does not mention using Plot.contour for functions. So I need help! This is what I’m trying to do:

Plot.plot({
  marks: [
    Plot.contour({
      fill: (x, y) => binorm(x, y, 0),

      x1: -3,
      y1: 3,
      x2: 3,
      y2: 3
    })
  ]
})

where binorm(x,y,r) is the pdf for the bivariate normal distribution, which I’ve tested and it is outputting correct values in the range of 0 to about 0.16. But nothing appears. My simple notebook is at Bivariate Normal Distribution / Seeing Statistics | Observable

I think you want y1: -3 instead of 3

Yep. To realize @Fil’s suggestion:

Plot.plot({
  marks: [
    Plot.contour({
      fill: (x, y) => binorm(x, y, 0),
      x1: -3,
      y1: -3,
      x2: 3,
      y2: 3
    })
  ]
})

I’ve also updated the notebook to include a simpler non-faceted example.

ack! very sorry for the dumb mistake on the limits! thanks for your kind debugging. Here is the working version where the user can change the probability between x and y in the standard bivariate normal distribution.

1 Like