0
$\begingroup$

Lets say I have a list of number:

data={2,3,4,5,9,7,4,8,9}

Can we plot a ContourPlot or ListContourPlot from list?

Or

Should it needed to be save in the following form,

y=0 and x goes from [1,2,3]

data[x_,y_]={2,3,4}

y=1 and x goes again from [1,2,3]

data[x_,y_]={5,9,7}

y=2 and x goes again from [1,2,3]

data[x_,y_]={4,8,9}

How can the ContourPlot works in any of the above form?

$\endgroup$
1
  • 4
    $\begingroup$ Read the help of "ListContourPlot" $\endgroup$ Mar 21, 2023 at 15:18

2 Answers 2

1
$\begingroup$
Clear["Global`*"]

data = {2, 3, 4, 5, 9, 7, 4, 8, 9};

data2 = Flatten[Table[{x, y, data[[3*y + x]]}, {y, 0, 2}, {x, 1, 3}], 
  1]

(* {{1, 0, 2}, {2, 0, 3}, {3, 0, 4}, {1, 1, 5}, {2, 1, 9}, {3, 1, 7}, {1,
   2, 4}, {2, 2, 8}, {3, 2, 9}} *)

ListContourPlot[data2]

enter image description here

$\endgroup$
1
$\begingroup$

The documentation center in mathematica is your friend. If you check the documentation of either ContourPlot and ListContourPlot you will see that there are two basic differences:

Since you are dealing with a list, the one you want is the ListContourPlot.


How to use ListContourPlot

Contours are a way to tell you the points that have an equal value.

Think of a mountain: You need an x position, a y position and a z position (height). You essentially create a 3D map and contours tell you which are the points which have the same z-value.

At the moment you are only providing a 1D list which is not enough. I will use your data as a basis to make a 3D dataset. All I'm doing is to create a 'mountain' where at each step along the y, the values of your mountain 'slice' increase by a factor of 1,2,3,....

I'm using 3 different plotting styles to help you visualise it better. They all show the same stuff, just slightly differently.

data = {2, 3, 4, 5, 9, 7, 4, 8, 9};
{ListContourPlot[{data, 2 data, 3 data}],
 ListDensityPlot[{data, 2 data, 3 data}],
 ListPlot3D[{data, 2 data, 3 data}, 
  ColorFunction -> "TemperatureMap"]}

enter image description here

If this is still unintuitive for you, simply replace your data with

data = Range[10];

and see how the new plots behave. I hope this will help you better understand your data and how you want to look at them.

Best,

A.

$\endgroup$

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