Plot not robust with respect to Inf values

Jaroslav Hajek highegg at gmail.com
Sun Aug 24 00:46:31 CDT 2008


On Sun, Aug 24, 2008 at 7:43 AM, Jaroslav Hajek <highegg at gmail.com> wrote:
> On Thu, Aug 21, 2008 at 9:30 PM, John W. Eaton <jwe at bevo.che.wisc.edu> wrote:
>> On 21-Aug-2008, John W. Eaton wrote:
>>
>> | On  6-Aug-2008, gOS wrote:
>> |
>> | |
>> | | Attempting to pass Inf or NaN to plot results in interestingly different
>> | | results, and there's a bug somewhere in it.
>> | |
>> | | plot(NaN,NaN) results in
>> | | error: plot: expecting first argument to be asex handle ... etc
>> | |
>> | | plot(Inf,Inf) results in
>> | | line 15: undefined variable: Inf
>> | |
>> | | gnuplot> plot "-" using ($1):($2) axes x1y1 title "" with lines ...
>> | |
>> | | I'd assume that there is some sort of failure on all graphics packages. As
>> | | Inf and NaN can appear in matrices, shouldn't plot be able to identify when
>> | | its passed data it shouldn't be passed?
>> | |
>> | | I view this as a bug. Matlab simply returns a blank plot while not crashing,
>> | | if this isn't possible in Octave for each back end it probably needs to be
>> | | handled.
>> | |
>> | | Even getting an error from Octave instead of gnuplot would be good enough
>> | | for me, currently operations procede if Inf is present so there is no way to
>> | | catch on the issue besides checking every value in the matrix before
>> | | plotting.
>> |
>> | Please try the following change.
>> |
>> | jwe
>>
>> Sorry, that was the wrong changeset file.  The correct one is
>> attached below.
>>
>> jwe
>>
>>
>> # HG changeset patch
>> # User John W. Eaton <jwe at octave.org>
>> # Date 1219346938 14400
>> # Node ID 2f7ff06c0c7b0f28ea726b304c8a5afdc7788ccd
>> # Parent  d54f113aa9839a33022065acc0d0250b53bb0dea
>> __go_draw_axes__.m (__gnuplot_write_data__): write "Inf Inf\n" if all data pairs contain NaN values
>>
>> diff --git a/scripts/ChangeLog b/scripts/ChangeLog
>> --- a/scripts/ChangeLog
>> +++ b/scripts/ChangeLog
>> @@ -1,3 +1,9 @@
>> +2008-08-21  John W. Eaton  <jwe at octave.org>
>> +
>> +       * plot/__go_draw_axes__.m: Fix test for have_data.
>> +       (__gnuplot_write_data__): Write "Inf Inf\n" if all data pairs
>> +       contain NaN values.
>> +
>>  2008-08-21  Thomas Treichl  <Thomas.Treichl at gmx.net>
>>
>>        * optimization/sqp.m: Increase test script tolerance.
>> diff --git a/scripts/plot/__go_draw_axes__.m b/scripts/plot/__go_draw_axes__.m
>> --- a/scripts/plot/__go_draw_axes__.m
>> +++ b/scripts/plot/__go_draw_axes__.m
>> @@ -1021,7 +1021,7 @@
>>       fputs (plot_stream, "unset hidden3d;\n");
>>     endif
>>
>> -    have_data = (! (isempty (data) || any (cellfun (@isempty, data))));
>> +    have_data = (! (isempty (data) || all (cellfun (@isempty, data))));
>>
>>     if (isempty (xlim))
>>       return;
>> @@ -1461,15 +1461,19 @@
>>       n = columns (data);
>>       have_nans = true;
>>       num_nan_elts = numel (nan_elts);
>> -      k = 1;
>> -      for i = 1:n
>> -       if (have_nans && i == nan_elts(k))
>> -         fputs (plot_stream, "\n");
>> -         have_nans = ++k <= num_nan_elts;
>> -       else
>> -         fprintf (plot_stream, fmt, data(:,i));
>> -       endif
>> -      endfor
>> +      if (num_nan_elts == n)
>> +       fputs (plot_stream, "Inf Inf\n");
>> +      else
>> +       k = 1;
>> +       for i = 1:n
>> +         if (have_nans && i == nan_elts(k))
>> +           fputs (plot_stream, "\n");
>> +           have_nans = ++k <= num_nan_elts;
>> +         else
>> +           fprintf (plot_stream, fmt, data(:,i));
>> +         endif
>> +       endfor
>> +      endif
>>     endif
>>   elseif (nd == 3)
>>     ## FIXME -- handle NaNs here too?
>> diff --git a/scripts/plot/print.m b/scripts/plot/print.m
>> --- a/scripts/plot/print.m
>> +++ b/scripts/plot/print.m
>> @@ -423,7 +423,7 @@
>>     endif
>>
>>     if (! isempty (convertname))
>> -      command = sprintf ("convert '%s' '%s'", name, convertname);
>> +      command = sprintf ("convert '%s' '%s'", name, convertname)
>>       [errcode, output] = system (command);
>>       unlink (name);
>>       if (errcode)
>>
>> _______________________________________________
>> Bug-octave mailing list
>> Bug-octave at octave.org
>> https://www-old.cae.wisc.edu/mailman/listinfo/bug-octave
>>
>>
>
> I transplanted this changeset without the removed semicolon in
> print.m. John, please fix it if it was a mistake; otherwise, let me
> know and I'll fix it.
>
OK, I see this is fixed by the next changeset. Sorry for the noise.


-- 
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


More information about the Bug-octave mailing list