In Mathematica 8.

Given this:

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*)

I'm trying to plot the level curves

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

I have the next error message:

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]"

I tried using:


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

what I should do?

  • $\begingroup$ I had no problem evaluating what you provided (screenshot). Which version of MMA are you using? Mine's 10. $\endgroup$
    – seismatica
    Jul 16 '14 at 23:07
  • $\begingroup$ @seismatica His post started with [Mathematica 8] though the formatting may have made it difficult to read. $\endgroup$
    – Mr.Wizard
    Jul 17 '14 at 0:02

There are several problems here. First, you are mixing syntax for two different systems: the old (poor) Plot Legends package from version 8 and prior, and the new improved integrated legend functions in version 9 and later. The old package used the Option name PlotLegend while the new one uses PlotLegends, which I admit is confusing.

The second problem is that the Plot Legends package does not work for ContourPlot directly:

There are two ways to use the functions in this package to place a legend in a graphic: the first can only be used as an option to the built-in functions Plot, ListPlot and ListLinePlot, while the second can be applied to any graphic.

You would need to manually specify the legend:

enter image description here

Something like this generic example from the documentation:

  DensityPlot[Sin[x y], {x, 0, π}, {y, 0, π}],
  {ColorData["LakeColors"][1 - #1] &, 10, " 1", "-1", LegendPosition -> {1.1, -0.4}}

enter image description here

Frankly I wouldn't bother however as almost no one likes the look of those legends. Instead you could roll your own and use Inset, or use Jens's solution from:


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.