0
$\begingroup$

I'm having a problem to plot a finite element solution. I have one array of orinal coordinates and an array with the new coordinates that I want to compare to the original array. The problem occurs when I try to use the ListPlot function. The ListPlot connect the wrong points. Here is the code:

allcoords = {{{0, 0}, {2, 0}, {2, 2}, {0, 2}}, {{2, 0}, {4, 0}, {4, 
     2}, {2, 2}}, {{4, 0}, {6, 0}, {6, 2}, {4, 2}}, {{6, 0}, {8, 
     0}, {8, 2}, {6, 2}}, {{0, 2}, {2, 2}, {2, 4}, {0, 4}}, {{2, 
     2}, {4, 2}, {4, 4}, {2, 4}}, {{4, 2}, {6, 2}, {6, 4}, {4, 
     4}}, {{6, 2}, {8, 2}, {8, 4}, {6, 4}}};
tabdeformed = {{0.1298087, 0.}, {2.11861, 0.`}, {4.09145241, 
    0.`}, {6.04989819195069`, 0.`}, {8.`, 0.`}, {8.`, 
    2.1329644641693166`}, {6.042519693730256`, 
    2.122638305596309`}, {4.078337372835341`, 
    2.0936720451127013`}, {2.101748416923281`, 
    2.0528629576754973`}, {0.11109027800216474`, 
    2.010820010989869`}, {8.`, 
    4.262007609299412`}, {6.016203961015385`, 
    4.241797525456124`}, {4.03110886320685`, 
    4.185184098398641`}, {2.04359292365999`, 
    4.103056727380703`}, {0.05011706001719006`, 4.018270354896997`}};
undefplot = 
  ListLinePlot[allcoords, AspectRatio -> Automatic, 
   PlotMarkers -> Automatic, Joined -> True];
defplot = 
  ListLinePlot[tabdeformed, AspectRatio -> Automatic, 
   PlotMarkers -> {Automatic, 12}, PlotStyle -> {Thick, Red, Dashed}];
Show[defplot, undefplot]
$\endgroup$
  • 1
    $\begingroup$ It's not clear what do you mean by "connect the wrong points". Which points do you want to connect? Please describe what is the desired output. $\endgroup$ – corey979 Dec 28 '16 at 22:57
  • $\begingroup$ Each original point has a coordinate. The Finite Element solution is the original coordnate plus the solution, wich is small. When i mean wrong, i mean that the coordinates at the plot are comparing different coordinates. $\endgroup$ – Diogo Dec 28 '16 at 23:01
  • $\begingroup$ You should also know that Show does not take the plot options the way you think it will. See Plot Option Precedence while combining Plots with Show[] and Why does the order of arguments in Show influence the result?. $\endgroup$ – corey979 Dec 28 '16 at 23:20
1
$\begingroup$

Is this what you want?

nf = Nearest[tabdeformed]

tabdeformed2 = 
 ArrayReshape[#, Dimensions@allcoords] & @
  Flatten[nf @ Flatten[allcoords, 1], 1]

undefplot = 
  ListLinePlot[allcoords, AspectRatio -> Automatic, 
   PlotMarkers -> Automatic, Joined -> True];
defplot = 
  ListLinePlot[tabdeformed2, AspectRatio -> Automatic, 
   PlotMarkers -> {Automatic, 12}, 
   PlotStyle -> {Thick, Red, Dashed}];
Show[defplot, undefplot]

enter image description here

$\endgroup$
  • $\begingroup$ Exactly! Thank you! $\endgroup$ – Diogo Dec 28 '16 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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