1
$\begingroup$

I'm trying to make a contour plot for multiple values of the same function.

To accomplish that, I'm doing the following:


lst = Table[x^2 - y^2 == i, {i, -100, 100, 10} ]

ContourPlot[lst, {x,-10,10}, {y,-10,10}]

But it produces an empty plot (it's blank).

However, if I paste the contents of the list into the command, i.e.,

ContourPlot[
 {x^2 - y^2 == -100, x^2 - y^2 == -90, x^2 - y^2 == -80, 
 x^2 - y^2 == -70, x^2 - y^2 == -60, x^2 - y^2 == -50, 
 x^2 - y^2 == -40, x^2 - y^2 == -30, x^2 - y^2 == -20, 
 x^2 - y^2 == -10, x^2 - y^2 == 0, x^2 - y^2 == 10, x^2 - y^2 == 20, 
 x^2 - y^2 == 30, x^2 - y^2 == 40, x^2 - y^2 == 50, x^2 - y^2 == 60, 
 x^2 - y^2 == 70, x^2 - y^2 == 80, x^2 - y^2 == 90, x^2 - y^2 == 100},
 {x, -10, 10}, {y, -10, 10}]

it works.

What's is the difference between using lst, instead of the whole list within ContourPlot[].

Contour Plot

$\endgroup$
1
  • $\begingroup$ If you don't need to distinguish the contours by color, there is an easier method: ContourPlot[x^2 - y^2, {x, -10, 10}, {y, -10, 10}, Contours -> Range[-100, 100, 10], ContourShading -> None]. $\endgroup$ Commented Mar 18, 2020 at 2:13

2 Answers 2

3
$\begingroup$

You need to Evaluate the expression.

ContourPlot[Evaluate@lst, {x, -10, 10}, {y, -10, 10}]

enter image description here

$\endgroup$
0
$\begingroup$

We can use x^2 - y^2 as the first argument of ContourPlot with the option ContourShading -> None (as suggested by JM in comments) and get colored contours using the form $\{\{level_1, style_1\},\ldots\}$ for setting the option Contours:

levels = Range[-100, 100, 10];
colors = ColorData[97] /@ Range[21];

contours = Transpose[{levels, colors}]

enter image description here

ContourPlot[x^2 - y^2, {x, -10, 10}, {y, -10, 10}, 
 Contours -> contours, BaseStyle -> Thick, ContourShading -> None]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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