LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

PlotXY not working for arrays including NaNs

Solved!
Go to solution

Hi,

 

working on this problem I was using (as usual) the PlotXY command for debugging, as follows:

plot_handle=PlotXY(panel_handle,PANEL_GRAPH,x,y_l,1001,VAL_DOUBLE,VAL_DOUBLE,VAL_THIN_LINE,VAL_NO_POINT,VAL_SOLID,1,VAL_RED );

 

Nothing spectacular besides the fact that the plot shows only zeros if the y array includes NaNs.

 

23480iC2BA5389BDC19F2F

 

This is (at least) a non-documented feature....

 

If the data array consists of say 100 NaNs and 900 valid numbers I would have expected the function to display the 900 valid numbers. Also one could have expected an error but the function returns a valid plot handle.

 

Is there no possibility to display the valid numbers?

 

Thanks,

 

Wolfgang

 

 

0 Kudos
Message 1 of 10
(4,406 Views)
Solution
Accepted by topic author Wolfgang

Wolfgang,

 

The expected behavior is that the valid points are plotted and the NaNs are skipped. But note that, if you choose a line plot, you need to have at least two consecutive valid points, otherwise you will see no line segments at all. You might obtain a better display if you use VAL_CONNECTED_POINTS or VAL_SCATTER.

 

Also, NaNs don't contribute to the new axis limits, if your axes are autoscaled. Your X-axis range seems to be (-10,0.8). If it's being autoscaled, might that be the extent of your x-data, considering only the valid points? And are all you valid y-values 0? Note that NaNs should simply be skipped -- they should not become 0. Therefore, a flat line of zeros is definitely unexpected.

 

Also, since this is an XY plot, all it takes is for one of the two values at a given index to be a NaN for the entire point to be skipped.

 

Luis

Message 2 of 10
(4,380 Views)

Hi Luis,

 

Thanks for your reply! Indeed I am pretty sure that the y array consists of a large number of consecutive valid numbers that are different from zero, however it starts with NaNs. I will export the array and upload it tomorrow for inspection. The x array is fully valid and covers the range displayed by the graph (autoscale).

 

Wolfgang

0 Kudos
Message 3 of 10
(4,369 Views)

Hi Luis,

 

so after checking everything twice I can tell you that I did not see the expected behavior... I have even tried scatter points Smiley Happy

 

The interesting thing is that the graphical array view works as you expected it to work, I am attaching the two views below. So in one dimension the CVI plot routines are able to deal with NaNs, but not the two dimensional PlotXY version. I am also attaching the two data sets allwoing you to confirm this behavior...

23564iD37AB6E8683AD33423566i873181A37B30AEBC

 

Thanks, Wolfgang

Download All
0 Kudos
Message 4 of 10
(4,356 Views)

Thanks, Wolfgang.

 

I do see a problem, but I'm still not convinced that the problem is in the graph control. When I took your data and tested it, I saw the same flat line you did. But in looking at it some more, I noticed that I was actually passing zeros to the plotting function. I used FileToArray to read the data from your files, and it seems as if it is this function that is not handling NaNs very well.

 

Here's the code I used:

 

FileToArray ("x.txt", x, VAL_DOUBLE, 1001, 1, VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_COLUMNS,

    VAL_ASCII);
FileToArray ("y.txt", y_1, VAL_DOUBLE, 1001, 1, VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_COLUMNS,

    VAL_ASCII);
PlotXY (panel, GRAPHTEST_GRAPH, x, y_1, 1001, VAL_DOUBLE, VAL_DOUBLE, VAL_THIN_LINE,

    VAL_SMALL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);

 

However, if I replace the second FileToArray call with the code below, which approximates the values that were actually in y.txt, it is plotted correctly:

 

for (i = 0; i < 1001; i++)
    if (i < 836)
        y_1[i] = NotANumber();
    else
        y_1[i] = 0.65 + 2 * (i - 836) / 165.0;

 

So, my question is, are you also writing and then reading the date before plotting it, or are you plotting it directly after you obtain it from the GaussHG function?

 

Luis

 

Message 5 of 10
(4,327 Views)

Hi Louis,

 

Thanks for your investigations!

 

I am not writing or reading the data to or from a file. The code actually is just the loop to calculate the vaules

 

for ( index = 0;
          index <= 1000;
          index ++ )
    {
        x [ index ] = -10.0 + index * 0.0108;
        y_1 [ index ] = GaussHG ( x [ index ], 0.5, 2.0, 1.5 );
    }

 

and the command to plot them

 

plot_handle=PlotXY(panel_handle,PANEL_GRAPH,x,y_l,1001,VAL_DOUBLE,VAL_DOUBLE,VAL_THIN_LINE,VAL_NO_POINT,VAL_SOLID,1,VAL_RED );

 

that's all...

 

if you wish, I can upload the complete project (tomorrow...)

 

Wolfgang

0 Kudos
Message 6 of 10
(4,318 Views)

Hi Luis,

 

it's embarassing and I ought to wear glasses... you were right, the plotxy function is behaving properly as long as the user is displaying the correct values... stupid me, I was calculating y_1 but displaying y_l, could not have been much worse...

 

Sorry for the false alarm concerning PlotXY, but the raw data obtaine from GaussHG still look odd...

 

Wolfgang

0 Kudos
Message 7 of 10
(4,300 Views)

Ah, that's good. At least I know that the plotting fuctions are okay. But I still think there's a problem with FileToArray, which I need to look into sometime. Maybe those functions just don't support NaN. But when I saw the "NaN"s in your file, and since I was assuming that you had created those files with ArrayToFile, I thought this might also be a bug. You say you haven't read or written any files. So how did you create those two files?

 

By the way, soon someone (not me) should be looking into the specifics of the problem you're having with GaussHG.

 

Luis

0 Kudos
Message 8 of 10
(4,270 Views)

So how did you create those two files?


Hi Luis,

 

for exporting the data I was using the variable window - some time ago you told me about the possibility to export arrays to a file Smiley Happy

 

Wolfgang

0 Kudos
Message 9 of 10
(4,260 Views)

Oh, man. Smiley Tongue

 

0 Kudos
Message 10 of 10
(4,251 Views)