1
$\begingroup$

Here is an example in ListContourPlot

ListContourPlot[Table[Sin[i + j^2], {i, 0, Pi, 0.1}, {j, 0, Pi, 0.1}], DataRange -> {{0, Pi}, {0, Pi}}]

Now, we only plot the contour for a specific value with ContourPlot, say, 0.6

ContourPlot[Sin[i + j^2] == 0.6, {i, 0, Pi}, {j, 0, Pi}]

The two commands yield left and right figures, respectively.

enter image description here

It can be found that they will become consistent after flipping the later with respect to its left-up to right-down diagonal.

My question is how can we get a consistent figure with ContourPlot in the sense of the contour shape. It will be much better if someone could explain the strange behaviors with ListContourPlot and ContourPlot. Thank you in advance.

$\endgroup$
5
  • 2
    $\begingroup$ In the Table, i is y (rows) and j is x (columns). In the other plot, i is x and j is y. It's just like this because when you construct matrices (rank 2 lists) you're actually building lists of lists. $\endgroup$
    – flinty
    Jul 5, 2020 at 15:36
  • $\begingroup$ The documentation for ListContourPlot states that "ListContourPlot[array] arranges successive rows of array up the page, and successive columns across." Since in your ContourPlot the "up the page" axis is the j axis, to get the same result with ListContourPlot, the rows, i.e., first index in Table, must be the j variable. $\endgroup$
    – Bob Hanlon
    Jul 5, 2020 at 15:59
  • $\begingroup$ @BobHanlon thank you for your reply. Well, for DataRange -> {{range1}, {range2}} in ListContourPlot, do {range1} and {range2} correspond to "across the page" and "up the page", respectively? I have read the documentation, it seemes no explanation on this. $\endgroup$
    – user55777
    Jul 6, 2020 at 2:42
  • $\begingroup$ @user55777 - Yes. Look at ListContourPlot[ Table[i + j, {i, 0, 5, 0.1}, {j, 0, 10, 0.1}], DataRange -> {{0, 10}, {0, 5}}] to verify. $\endgroup$
    – Bob Hanlon
    Jul 6, 2020 at 3:01
  • $\begingroup$ @BobHanlon thank you, sir. $\endgroup$
    – user55777
    Jul 6, 2020 at 3:17

1 Answer 1

1
$\begingroup$

Change the order of iterators in ContourPlot:

cp = ContourPlot[Sin[i + j^2] == 0.6, {j, 0, Pi}, {i, 0, Pi}, 
  ContourStyle -> Directive[Red, Thick]]

enter image description here

Show[ListContourPlot[Table[Sin[i + j^2], {i, 0, Pi, 0.1}, {j, 0, Pi, 0.1}], 
    DataRange -> {{0, Pi}, {0, Pi}}], cp]

enter image description here

$\endgroup$
0

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.