The second form of ListContourPlot expects a list of triplets: {{x1,y1,f1},{x2,y2,f2},...}
. So your question is how to combine two lists coordinates
and values=sigmaelement[[1,All,1]]
in one list of correct form. There are many possible ways to do this.
Straightforward using Table
:
tab[coordinates_, values_]:= Table[{coordinates[[i, 1]], coordinates[[i, 2]], values[[i]]}, {i, 1, Length@values}]
Using Transpose
and mapping transformation function over the list:
map[coordinates_, values_]:={#1[[1, 1]], #1[[1, 2]], #[[2]]} & /@Transpose@{coordinates, values};
or using replacement rules (in my opinion this one is the most clear):
repl[coordinates_, values_]:=Transpose@{coordinates, values} /. {{x_, y_}, z_} -> {x, y, z}
or using Flatten
(thanks to @corey979):
cor1[coordinates_, values_]:=Flatten[#, 1] & /@ Transpose[{coordinates, values}]
or using ArrayReshape
(thanks to @corey979 again):
cor2[coordinates_, values_]:=ArrayReshape[Transpose@{coordinates, values}, {Length@values, 3}]
Using MapThread
to avoid transposing
mapTr[coordinates_, values_]:=MapThread[#1~Join~{#2} &, {coordinates, values}]
Since we have many options let's run quick performance benchmark for $10^6$ elements. I added two other functions from @m_goldberg's answer.
genData[n_] := {RandomReal[1.0, {n, 2}], RandomReal[1.0, {n}]};
funList = {tab, map, mapTr, cor1, cor2, repl, mg1, mg2};
timingFun[funList_, {c_, v_}] := First@AbsoluteTiming[#[c, v]] & /@ funList;
timings = timingFun[funList, genData[10^6]]
BarChart[{timings}, ChartElementFunction -> "GlassRectangle",
ChartStyle -> "Pastel", ChartLabels -> funList]

So Table
is a clear winner.
Length @ sigmaelement[[1, All, 1]]
the same asLength @ coordinates
? I.e. arecoordinates
ordered to matchsigmaelement[[1, All, 1]]
? $\endgroup$ListContourPlot[ Transpose@{coordinates, sigmaElement[[1,All,1]]} /. {{x_, y_}, z_} -> {x, y, z}]
$\endgroup$