If you plot a two variable function like $x^2+y^2$, you get a series of circles with lines and colored areas. My question is, what do the lines and the colored areas represent?

  • $\begingroup$ Try this experiment: ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi}], followed by Plot3D[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi}] and compare the two. Now try ContourPlot[x^2 + y^2, {x, -4, 4 }, {y, -4, 4 }] and Plot3D[x^2 + y^2, {x, -4, 4 }, {y, -4, 4 }]. Got it? ContourPlot by default generates colorized grayscale output, in which larger values are shown lighter. You may also like to read: en.wikipedia.org/wiki/Contour_line and itl.nist.gov/div898/handbook/eda/section3/contour.htm $\endgroup$
    – Moo
    Apr 23, 2016 at 12:50
  • $\begingroup$ @Moo, OK, so now I know why there are areas of different colors but what is the meaning if the lines bounding each colored area? Do they represent something? $\endgroup$
    – MrDi
    Apr 23, 2016 at 12:56
  • 1
    $\begingroup$ It's explained well here: en.wikipedia.org/wiki/Contour_line The value of the function doesn't change as you move along a contour. $\endgroup$
    – Szabolcs
    Apr 23, 2016 at 13:10
  • $\begingroup$ @MrDi: There needs to be a way to select peaks and valleys and to bound them somehow, so they use some algorithm that picks those areas. I think you can find some details on the Wiki link I provided. it sounds like you get it, think of it as trying to collapse a 3D image onto a 2D surface. These diagrams can be extremely useful. The lines are just separating areas where something is changing based on some algorithm. $\endgroup$
    – Moo
    Apr 23, 2016 at 13:13
  • $\begingroup$ @Moo, OK, thanks for help. $\endgroup$
    – MrDi
    Apr 23, 2016 at 13:14

1 Answer 1


It might be easier for you to see the correspondence between a contour plot and a surface plot if you plot them side-by-side like this (code adapted from here):

peaks[x_, y_] := 3 (1 - x)^2 Exp[-x^2 - (y + 1)^2] - 10 (x/5 - x^3 - y^5) Exp[-x^2 - y^2] -
                 Exp[-(x + 1)^2 - y^2]/3

With[{c = Subdivide[-5, 5, 10]}, 
     GraphicsRow[{ContourPlot[peaks[x, y], {x, -3, 3}, {y, -3, 3}, 
                              ColorFunction -> "DarkTerrain",
                              Contours -> c, PlotRange -> All], 
                  Plot3D[peaks[x, y], {x, -3, 3}, {y, -3, 3}, BoundaryStyle -> None, 
                         Boxed -> False, ColorFunction -> "DarkTerrain", 
                         MeshFunctions -> {#3 &}, Mesh -> {c}, PlotRange -> All, 
                         ViewPoint -> {0, -2.7, 3.}]}]]

some interesting terrain

where I took the opportunity to use a function with more interesting contours. (Unfortunately, I don't know of any way to refine the meshlines produced by MeshFunctions; if you know a way, let me know in the comments!)

As noted in the comments above, the contours in ContourPlot[] are so-called isoclines; that is, lines of constant altitude ($z$ value). The interpretation of the colors depends on what colormap you're using; in this case, I used the "DarkTerrain" color gradient, which goes like this:

"DarkTerrain" color gradient

where the bluish color ("water") corresponds to the valleys, the whitish color ("snowcap") corresponds to the peaks, and the earthy colors corresponds to intermediate values. If you are familiar with map reading, running along isoclines corresponds to staying at a constant (flat) altitude, and crossing the isoclines corresponds to either ascent or descent.

A biographical segue: I was a Boy Scout once upon a time, and map reading was de rigueur for Scouts who wanted to have camping experience.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.