If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Contour plots

An alternative method to representing multivariable functions with a two-dimensional input and a one-dimensional output, contour maps involve drawing purely in the input space.  Created by Grant Sanderson.

Want to join the conversation?

  • duskpin ultimate style avatar for user Davide Ghazal
    You are brilliant!Keep up the good work......Is this topic of maths that explains atomic orbitals shapes?
    (48 votes)
    Default Khan Academy avatar avatar for user
    • piceratops seedling style avatar for user Jorge Luis Borges Vázquez
      Orbital shapes are only aproximated idealizations of statistical information about where is more probably that an electron is located at certain moment (this also is an aproximation since Heisenberg found that it is incompatible to describe the position and the time of an electron). Even in a perfect situation where an only atom is isolated from universe gravitation, electromagnetism..., the shape of the orbit (all space points where an electron could be al some point) wouldn't be an sphere, neither a surface. We could only say, for example, the probability of the orbit of this electron is between these two spherical surfaces (now, give two radios from nucleous) is 95%, or 99%, or 99,9999%... but it is imposible to draw an exact surface (remember a surface doesn't have thickness) outside of where an electron would never be (if we also idealize it like a spheric particle, and not a wave or another concept).

      P.S.: sorry if my english has many mistakes, I am from Spain
      (39 votes)
  • male robot hal style avatar for user Kunal Muley
    At in the video we see that the contour lines for z=1, not intersecting at point (0,0) in the X-Y plane.

    But at in the video, Grant marks a contour line as z=1 which intersects at pint (0,0) in the X-Y plane.

    Can please someone explain this difference?
    (12 votes)
    Default Khan Academy avatar avatar for user
  • primosaur ultimate style avatar for user Lucas Muehleisen
    Is there a way to determine if the graph is coming up out of the page or going into it based on the contour plot?
    (9 votes)
    Default Khan Academy avatar avatar for user
  • leafers ultimate style avatar for user jjakow
    Does anyone know what the function is being graphed?
    f(x,y) = ....?

    (7 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user Kaitlyn H
    When I was in middle school, I took a geography course that discussed contour plots as a 2-D method of representing altitude (although of course since it was a middle school course it didn't examine the math involved). I had often wondered how those maps were generated, but no one was able to explain the concept to me. Now I finally begin to understand how that works!

    Now I'm curious whether it's possible to develop multivariate equations to model and describe actual surfaces on the earth or on other celestial bodies. So in other words, just like how we might use the Lotka-Volterra Model differential equations to describe an actual predator-prey population relationship, is it similarly possible to find multivariate equations/models that can mathematically represent an actual surface on the earth? If so, how is that done, and can anyone show/describe to me some specific examples of when and how this was done?
    (8 votes)
    Default Khan Academy avatar avatar for user
  • primosaur ultimate style avatar for user FakePlunk
    Is the ever a need to slice the graphs in a diagonal sense, but keeping the center point of the plane in the z-axis constant?
    (4 votes)
    Default Khan Academy avatar avatar for user
    • leaf green style avatar for user Grant
      Hmmm, nothing comes to mind immediately. You think about diagonal slicing in the context of the directional derivative (a few videos down the road from this one), but in that case the plane you are using to slice things is oriented vertically (i.e., parallel to the z-axis), and it is only "diagonal" in that it intersects the xy-plane along a diagonal line.
      (7 votes)
  • starky ultimate style avatar for user Rayden
    At , is that Desmos Graphing Calculator?
    (4 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user Samir Huseynzade
    So we dont need to know what function represents this graph?
    Because as i am watching i dont feel comfortable with graph because it is your approach to shape. What can be unique approach to any graph? If there is another complex 3d graph how i can represent it?
    (3 votes)
    Default Khan Academy avatar avatar for user
    • starky seedling style avatar for user David Flewelling
      The contour lines we use to make a contour plot are a set of all x and y values which, together, produce a specific z-value.

      If you're working with some other 3D graph then, you'll want to check to find which values of x and y together produce z. The easiest way to do this is to set a fixed value for one variable and then solve for the other. So, if you have a function F (x,y) = 2x + 3y, and you want to create a contour line for z = 3. You'd pick some particular x value, like x=1, and then solve for y (which will give you y = 1/3, but for more complicated functions there could be many more possible y values). Then, repeat this for different x-values until you have an idea of the contour line for that z value. Making a contour plot by hand is just doing this over and over until you have enough points to give you an understanding of what is happening.
      (4 votes)
  • blobby green style avatar for user irinabains
    Which software has been used in this vid?
    (4 votes)
    Default Khan Academy avatar avatar for user
  • male robot hal style avatar for user Michael Robertson
    What does an intersection of contour lines mean? In the case of this graph, it happens on the origin.

    Similarly, what do contour curves that are lines represent? How does the slope or derivative of the contour curves relate to the original graph?
    (2 votes)
    Default Khan Academy avatar avatar for user

Video transcript

- [Voiceover] So I have here a three-dimensional graph, and that means that it's representing some kind of function that has a two-dimensional input and a one-dimension output. So that might look something like f of x, y equals and then just some expression that has a bunch of x's and y's in it. And graphs are great but they're kinda clunky to draw. I mean, certainly you can't just scribble it down. It typically requires some kind of graphing software and when you take a static image of it it's not always clear what's going on. So here I'm going to describe a way that you can represent these functions and these graphs two-dimensionally just by scribbling down on a two-dimensional piece of paper. This is a very common way that you'll see if you're reading a textbook or if someone is drawing on a blackboard. It's known as a contour plot and the idea of a contour plot is that we're going to take this graph and slice it a bunch of times. So I'm going to slice it with various planes that are all parallel to the x, y plane and let's think for a moment about what these guys represent. So the bottom one here represents the value z is equal to negative two. This is the z-axis over here and when we fix that to be negative two and let x and y run freely we get this whole plane. And if you let z increase, keep it constant, but let it increase by one to negative one we get a new plane, still parallel to the x, y plane but it's distance from the x, y plane is negative one. And the rest of these guys, they're all still constant values of z. Now in terms of our graph, what that means is that these represent constant values of the graph itself. These represent constant values for the function itself. So because we always represent the output of the function as the height off of the x, y plane these represent constant values for the output. What that's going to look like. So what we do is we say, "Where do these slices cut into the graph?" So I'm going to draw on all of the points where those slices cut into the graph and these are called contour lines. We're still in three-dimensions so we're not done yet. So what I'm going to do is take all these contour lines and I'm going to squish them down on to the x, y plane. So what that means, each of them has some kind of z component at the moment, and we're just going to chop it down, squish them all nice and flat, on to the x, y plane. And now we have something two-dimensional, and it still represents some of the outputs of our function. Not all of them, it's not perfect, but it does give a very good idea. I'm going to switch over to a two-dimensional graph here. And this is that same function that we were just looking at. Let's actually move it a little bit more central here. So this is the same function that we were just looking at, but each of these lines represents a constant output of the function so it's important to realize we're still representing a function that has a two-dimensional input and a one-dimensional output. It's just that we're looking in the input space of that function as a whole. So this is still f of x, y and then some expression of those guys but this line might represent the constant value of f when all of the values were at outputs three. Over here, this also, both of these circles together give you all the values where f outputs three. This one over here will tell you where it outputs two and you can't know this just looking at the contour plot so typically if someone's drawing it if it matters that you know the specific values they'll mark it somehow. They'll let you know what value each line corresponds to but as soon as you know that this line corresponds to zero it tells you that every possible input point that sits somewhere on this line will evaluate to zero when you pump it through the function. And this actually gives a very good feel for the shape of things. If you like thinking in terms of graphs you can kind of imagine how these circles and everything would pop out of the page. You can also look, notice how the lines are really close together over here, very, very close together, but they're a little more spaced over here. How do you interpret that? Well, over here this means it takes a very, very small step to increase the value of the function by one, very small step and it increases by one, but over here it takes a much larger step to increase the function by the same value. So over here this kind of means steepness. If you see a very short distance between contour lines it's going to be very steep but over here it's much more shallow. And you can do things like this to kind of get a better feel for the function as whole. The idea of a whole bunch of concentric circles usually corresponds to a maximum or a minimum, and you end up seeing these a lot. Another common thing people will do with contour plots as they represent them is color them. So what that might look like is here where warmer colors like orange correspond to high values and cooler colors like blue correspond to low values. The contour lines end up going along the division between red and green here, between light green and green, and that's another way were colors tell you the output and then the contour lines themselves can be thought of as the borders between different colors. And again a good way to get a feel for a multi-dimensional function just by looking at the input space.