Message Boards Message Boards

[?] Plot from inside a loop?

Posted 4 years ago

Hello everyone. I have a matrix of size 300321*8. The first two columns represent a series of values of latitude and longitude. The other six columns represent some quantities that I want to plot over a map. I have constructed a code. However, when I execute it there is no output in my screen.

This is my code:

For[i = 3, i < countMax + 3, i++,

 Xpos = aaa[[All, 1]]; Ypos = aaa[[All, 2]]; 
 windXVal = aaa[[All, i]]; 
 windXMat = Transpose[{Xpos, Ypos, windXVal}]; 
 ListContourPlot[windXMat //. {x_List} :> x, 
  PlotLegends -> Automatic]]

Here, countMax is defined as the dimension of aaa-2.

Can someone please tell me where is my mistake? Any answer is welcome. Regards. Jaime.

POSTED BY: Jaime de la Mota
4 Replies
Posted 4 years ago

Hi Jamie,

There is no need for the transposition and the replacement rule. Generate fake data, a 10 x 8 list where the first two values are a random GeoPosition latitude and longitude and the rest are random real values between 0 and 10.

SeedRandom[1];
aaa = Table[Join[RandomGeoPosition[]["LatitudeLongitude"], RandomReal[10, 6]], 10];

Generate plots for each of the 6 values

plots = Table[Map[#[[{1, 2, i}]] &, aaa], {i, 3, 8}] // Map[ListContourPlot];
plots // Partition[#, 3] & // Grid

enter image description here

POSTED BY: Rohit Namjoshi

In case you are interested into the functional programming approach, this may get you started:

aaa = RandomReal[{0, 1}, {10, 4}]

aaa //
   Transpose //
  ReplaceAll[{x_, y_, vals__} :> Map[{x, y, #} &, {vals}]] //
 Map[ListContourPlot]
POSTED BY: Gustavo Delfino

Put the command Print[…] around your ListContourPlot function.

POSTED BY: Sander Huisman

It works indeed.

Thank you very much.

POSTED BY: Jaime de la Mota
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract