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?
1 Answer
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.}]}]]
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:
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.
ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi}]
, followed byPlot3D[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi}]
and compare the two. Now tryContourPlot[x^2 + y^2, {x, -4, 4 }, {y, -4, 4 }]
andPlot3D[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$