3
$\begingroup$

I have this code, and it generates the below ListStreamPlot. The second graph is the ListStreamPlot overlaid with the points comprising the ListStreamPlot (extracted after looking at // InputForm); unfortunately, the extracted points also include the border points. These "border points" are not of predictable coordinates, so there doesn't seem to be an easy way to remove them from the set. (I want this code to be as case-inspecific as possible, since I am analyzing many additional data sets.)

Is there a simple way -- perhaps in the original ListStreamPlot code -- to remove the "border points" from the points list?

v3 = ListStreamPlot[vectorsT, StreamStyle -> "Line", StreamPoints -> 
  {{xcorT[[midpoint + 4]], ycorT[[midpoint + 4]]}}]

points = v3[[1, 2, 1]];

xPoints = Transpose[points][[1]]; 
yPoints = Transpose[points][[2]];

pointsOnly = ListPlot[Transpose[Join[{xPoints}, {yPoints}]]] ;

graph 1:

graph 2:

Entire source code

(* Set directory to that of this notebook *)
SetDirectory[NotebookDirectory[]];

(* Import CSV'd data *)
dat = Import["test_data2b.txt", "CSV"];

(* Divide data *)
datAll = Flatten[Partition[dat[[1]], 7]];
datAllCpy = datAll;

(* Divide data into components *)
(* ID *)

ID = Flatten[Partition[datAll, 1, 7]];
datAll = RotateLeft[datAll];

(* Longitude *)
LONG = Flatten[Partition[datAll, 1, 7]];
datAll = RotateLeft[datAll];

(* Latitude *)
LAT = Flatten[Partition[datAll, 1, 7]];
datAll = RotateLeft[datAll];

(* SFC_SPD *)
SPD1 = Flatten[Partition[datAll, 1, 7]];
datAll = RotateLeft[datAll];

(* SPF_SPD _KT *)
SPD2 = Flatten[Partition[datAll, 1, 7]];
datAll = RotateLeft[datAll];

(* SFC_SPD _MP *)
SPD3 = Flatten[Partition[datAll, 1, 7]];
datAll = RotateLeft[datAll];

(* SFC_DIR *)
DIR = Flatten[Partition[datAll, 1, 7]];

(* Restore original list *)
datAll = datAllCpy;

(* Make longtitudes negative *)
LONG = Abs[LONG];
LONG = 0 - LONG;

(* Convert from degrees to radians *)
DIR = DIR *(2 Pi/360);

(* Graph data as vectors *)
xcor = LONG;
ycor = LAT;
xvc = SPD1*Cos[DIR]; 
yvc = SPD1*Sin[DIR];
vectors = Table[{{xcor[[i]], ycor[[i]]}, {-yvc[[i]], -xvc[[i]]}}, {i, 1, Length[xcor]}];

(* Calculate midpoint of data *)
midpoint = Flatten[Position[SPD1, 0.]][[1]];

(* Transpose all points to be around origin *)
LONGT = LONG - (LONG[[midpoint]]);
LATT = LAT - LAT[[midpoint]]; 

(* Graph data as vectors *)
xcorT = LONGT;
ycorT = LATT;
xvcT = SPD1*Cos[DIR]; 
yvcT = SPD1*Sin[DIR];
vectorsT = Table[{{xcorT[[i]], ycorT[[i]]}, {-yvcT[[i]], -xvcT[[i]]}}, {i, 1, Length[xcor]}];

v3 = ListStreamPlot[vectorsT, StreamStyle -> "Line", StreamPoints -> {{xcorT[[midpoint + 4]], ycorT[[midpoint + 4]]}}]

points = v3[[1, 2, 1]]; 

xPoints = Transpose[points][[1]]; 
yPoints = Transpose[points][[2]];

pointsOnly = ListPlot[Transpose[Join[{xPoints}, {yPoints}]]] ;

Show[v3, pointsOnly]
$\endgroup$
  • 1
    $\begingroup$ Please include full executable code so that we can try this ourselves without first having to recreate your example. $\endgroup$ – Mr.Wizard Jan 22 '13 at 20:04
  • $\begingroup$ @Mr.Wizard Yes - I have added it above. $\endgroup$ – ueronica Jan 22 '13 at 20:22
  • 1
    $\begingroup$ Okay, but now we lack the test_data2b.txt file. Is it not possibly to give a smaller self-contained example of the problem? $\endgroup$ – Mr.Wizard Jan 22 '13 at 20:24
  • $\begingroup$ Yes, just about to address that. The data can be found here - docs.google.com/document/d/… $\endgroup$ – ueronica Jan 22 '13 at 20:32
3
$\begingroup$

You can extract the Line first, then extract the points on the line:

pts = Cases[v3,
   GraphicsComplex[c__] :>
    Cases[Normal[GraphicsComplex[c]],
     Line[pts_] :> pts, Infinity],
   Infinity] // Flatten[#, 2]& ;
Graphics[{Red, Point[pts]}, Frame -> True ]

Mathematica graphics

|improve this answer|||||
$\endgroup$
  • $\begingroup$ @ueronica You're welcome :) $\endgroup$ – Silvia Jan 22 '13 at 22:26
2
$\begingroup$

You could abuse the StreamColorFunction for this goal

res=
Reap[
  v3 = ListStreamPlot[vectorsT, 
          StreamStyle -> "Line", 
          StreamPoints -> {{xcorT[[midpoint + 4]], ycorT[[midpoint + 4]]}}, 
          StreamColorFunction -> ((Sow[{#1, #2}]; None) &)
       ]
];

ListPlot[res[[2]], AspectRatio -> Automatic]

Mathematica graphics

|improve this answer|||||
$\endgroup$

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.