I'm new using mathematica. I'm plotting a funcion that depends on two variables (r and C) let's say z= r^2+c^2

When I use ContourPlot, level curves are shown in a r-C plane. I'm trying to obtain the curves but in a r-Z plane and r-C Plane and if this were possible, gave a label to any curve

For instance, the curves in the r-Z plane has a different behaviour when I change C

Does anyone know how to do that? ? :S


  • 1
    $\begingroup$ Manipulate[ ContourPlot[r^2 + c^2 - z, {r, -2, 2}, {z, -2, 2}], {c, -2, 2}]. does this work for you? $\endgroup$ – Algohi Jul 16 '14 at 7:20
p1 = ContourPlot[r^2 + c^2, {r, -2, 2}, {c, -2, 2},
  ContourLabels -> 
   Function[{x, y, z}, Text[Framed[z], {x, y}, Background -> White]],
  ImageSize -> 400,
  PlotLegends -> Automatic];

p2 = Plot3D[r^2 + c^2, {r, -2, 2}, {c, -2, 2},
  MeshFunctions -> {#3 &},
  Mesh -> 7,
  MeshShading -> {Blue, LightBlue},
  ImageSize -> 400,
  Lighting -> "Neutral"];

Grid[{{p1, p2}}]

enter image description here

  • $\begingroup$ Thank you. I'm using Mathematica 8. PlotLegends->Automatic doesn't work :/ I had this error message: ContourPlot::optx: "Unknown option PlotLegends in ContourPlot[r^2+c^2,{r,-2,2},{c,-2,2},ContourLabels->Function[{x,y,z},Text[z,{x,y},Background->White]],ImageSize->400,PlotLegends->Automatic]" .. I've already tried using Needs["PlotLegends`"] and looking for a possible answer on the Internet. $\endgroup$ – YoJesseP Jul 16 '14 at 21:29

just for the sake of variety, here is another approach. From your problem it looks like you have an equation relating three variables and you want to choose two of them as variable. In most practical cases it is quite useful to treat the third variable as a parameter and take some trial value for that. Now say you have three variables x,y,z and you want a plot on xy plane, and say there is a given relation among them.

f[x_, y_, z_] := z - x^2 - y^2 (*relation among the variable f[x,y,z]==0*)
parameter = Range[0.1, 1, 0.1];(*choice of parameter values*)

ContourPlot[Evaluate@Table[f[x, y, z] == 0, {z, parameter}], {x, -1, 1}, {y, -1,1}, PlotLegends -> parameter]

PlotLegends will take care of the label. If you want to treat x as a parameter and want to plot on yz plane. Simply change the position of x and z like

ContourPlot[Evaluate@Table[f[x, y, z] == 0, {x, parameter}], {z, -1, 1}, {y, -1,1}, PlotLegends -> parameter]

And if you want the whole picture, use Contourplot3D (no need to set parameter)

ContourPlot3D[f[x, y, z], {x, -1, 1}, {y, -1, 1}, {z, -1, 1}]

Of course you can see the projections in all planes as well (click on the link.)

  • $\begingroup$ That was very useful! thanks. Nevertheless, I have this mistake: ContourPlot::optx: "Unknown option PlotLegends in ContourPlot[{0.1 -x^2-y^2==0,0.2 -x^2-y^2==0,0.3 -x^2-y^2==0,0.4 -x^2-y^2==0,0.5 -x^2-y^2==0,0.6 -x^2-y^2==0,0.7 -x^2-y^2==0,0.8 -x^2-y^2==0,0.9 -x^2-y^2==0,1. -x^2-y^2==0},{x,-1,1},{y,-1,1},PlotLegends->parameter]" :/ $\endgroup$ – YoJesseP Jul 16 '14 at 20:21
  • $\begingroup$ @YoJesseP, probably you are using V8 or less. You have to use Needs["PlotLegends"]` then. Type PlotLegend in your help menu and it will show you the details. $\endgroup$ – Sumit Jul 17 '14 at 8:48
  • $\begingroup$ Thanks Sumit. I've already fixed it. I've downloaded mathematica 10 and put your code. Thank you $\endgroup$ – YoJesseP Jul 19 '14 at 1:28

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.