1
$\begingroup$

I have a data set like below:

368 150 0.31895877
369 150 0.32141133
370 150 0.3190167
371 150 0.33890757
372 150 0.3649395
373 150 0.37585051
374 150 0.37916244
375 150 0.37619812
376 150 0.37287654
377 150 0.37249031
378 150 0.37102263
379 150 0.34839918
380 150 No Data
381 150 No Data
382 150 No Data
383 150 No Data
384 150 No Data
385 150 No Data
386 150 No Data
387 150 No Data
388 150 No Data
389 150 No Data
390 150 No Data
391 150 No Data
392 150 No Data

This data set sometimes contains "No Data" and I want to ListPointPlot3D with this data.

Therefore, I imported this data and plotted it:

data=Import["datafile.txt","Table"];
ListPointPlot3D[data]

As I expected, I got error about the invalid list.

How can I plot the graph with these No Data rows eliminated?


This is a sample file which I want to plot with.

datafile.txt

$\endgroup$
  • 1
    $\begingroup$ try data /. "No Data"->Missing[] $\endgroup$ – Mike Honeychurch May 12 '17 at 10:02
  • $\begingroup$ I tried data /. List[x__, "No", "Data"] -> Missing[], but I got error again when I plot the modified data... $\endgroup$ – Taiki Bessho May 12 '17 at 10:14
  • 1
    $\begingroup$ Please upload a small data file for us to work with. $\endgroup$ – Lotus May 12 '17 at 10:20
  • 2
    $\begingroup$ Try data/. {x_, y_, "No", "Data"} :> {x, y, Missing[]}. ListPointPlot3D doesn't like the Missing[] not sitting in a triple. $\endgroup$ – N.J.Evans May 12 '17 at 12:01
1
$\begingroup$

When I import your sample data with

data = Import[FileNameJoin[{$HomeDirectory, "Desktop", "data.txt"}], "Table"];

I get

data // InputForm
{{368, 150, 0.31895877}, {369, 150, 0.32141133}, {370, 150, 0.3190167}, 
 {371, 150, 0.33890757}, {372, 150, 0.3649395}, {373, 150, 0.37585051}, 
 {374, 150, 0.37916244}, {375, 150, 0.37619812}, {376, 150, 0.37287654}, 
 {377, 150, 0.37249031}, {378, 150, 0.37102263}, {379, 150, 0.34839918}, 
 {380, 150, "No", "Data"}, {381, 150, "No", "Data"}, {382, 150, "No", "Data"}, 
 {383, 150, "No", "Data"}, {384, 150, "No", "Data"}, {385, 150, "No", "Data"}, 
 {386, 150, "No", "Data"}, {387, 150, "No", "Data"}, {388, 150, "No", "Data"}, 
 {389, 150, "No", "Data"}, {390, 150, "No", "Data"}, {391, 150, "No", "Data"}, 
 {392, 150, "No", "Data"}}

It is easy to distinguish good points from bad. Good have have three elements; bad points have more. Therefore, I will simply select all data points which have three elements.

goodData = Select[data, Length[#] == 3 &];
ListPointPlot3D[goodData,
  PlotStyle -> PointSize[Large],
  PlotRange -> {Automatic, {149, 151}, {.3, .4}},
  BoxRatios -> {1, .5, 1},
  Ticks -> {Automatic, {150}, Automatic},
  Filling -> Bottom,
  FillingStyle -> Thick]

plot

$\endgroup$
1
$\begingroup$

The data gets imported as a single loooong string which needs to be split correctly and partitioned before plotting it. Here is something I came up with:

In[53]:= data = Import["datafile.txt"];

Note that Dimensions gives you { } and Head gives you String

In[54]:= Dimensions[data]

Out[54]= {}

In[55]:= Head[data]

Out[55]= String

Split and partition data correctly

In[56]:= sp = StringSplit[data, {"\n"}];

In[57]:= sp[[1]]

Out[57]= "217 135 No Data"

In[58]:= sp2 = StringReplace[#, "No Data" -> "NoData"] & /@ sp;

sp3 = StringSplit /@ sp2;

In[60]:= Head[sp3[[1, 1]]]

Out[60]= String

Use ToExpression to convert strings looking like numbers to actual numbers.

In[61]:= Map[ToExpression, sp3, {2}];

In[62]:= ListPointPlot3D[%]
$\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.