help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: text (...) function behaviour for large numbers? Bug?


From: David Bateman
Subject: Re: text (...) function behaviour for large numbers? Bug?
Date: Wed, 05 Dec 2007 17:01:56 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

Matthias Brennwald wrote:
> Dear all
>
> I tried to use the text(...) command for text labels in a plot with 
> large numbers. For y coordinates larger than 2E9, the text is not placed 
> correctly. Try this to see what I mean:
>
> --------------
> plot(rand(1,10)*1e10)
> axis ([1 10 1e8 1e10]);
> text(2,1e9,'1E9')
> text(3,2e9,'2E9')
> text(4,3e9,'3E9')
> text(5,4e9,'4E9')
> text(6,5e9,'5E9')
> --------------
>
> Matthias
>
>
>   
The gnuplot code generated by the last of these in 2.9.17+ is

set label "{/helvetica 5E9 }" at  6,5000000000 font "helvetica,10" left
rotate by 0.000000 textcolor lt -1;

which is correct. However, it seems that gnuplot is not respecting the
"5000000000" string for the y placement and is ceilinged at 2e9. It is
interesting to not that 2e9 is approximately 2^31, so in the case above
gnuplot is parsing the "5000000000" with an signed 32-bit integer.
However changing the text to

set label "{/helvetica 5E9 }" at  6,5e9 font "helvetica,10" left rotate
by 0.000000 textcolor lt -1;

and the label prints correctly. So gnuplot isn't always treating this as
signed 32-bit integer. A simple fix is just to force octave to use
mantissa/exponent formating for labels with positions greater than 1e9
(which the attached patch does). However, then if you do something like

plot (1e10 +  1e-6* [1:10])
axis([1 10 1e10-1e6 1e10+1e7])
text(2,1e10+5e-6,"label")

it won't work.. So it would be better to get gnuplot to respect the
"5000000000" value.

However, In fact the above doesn't seem to work for another reason, in
that the plot data itself is incorrectly written by octave. This can be
seen with

x = 1e10 +  1e-6* [1:10];
printf("%.15g\n", x);

which duplicates the same thing as __go_draw_axes__.m. It seems that all
of the %.15g in __go_draw_axes__.m need to be %.16g. Try

x = 1e10 +  1e-8* [1:10];
x(1) == x(end)
x = 1e10 +  5e-7* [1:10];
x(1) == x(end)
printf("%.16g\n", x);

that confirms that all 53 bits of a double floating point are printed
with %.16g. However, even though octave then outputs the data correctly
to gnuplot, it is still misinterpreted. Not sure what to do here..


D.






-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

*** ./scripts/plot/__go_draw_axes__.m.orig47    2007-12-05 16:36:45.714490401 
+0100
--- ./scripts/plot/__go_draw_axes__.m   2007-12-05 16:35:51.079216677 +0100
***************
*** 930,941 ****
  
          if (nd == 3)
            fprintf (plot_stream,
!                    "set label \"%s\" at %s %.15g,%.15g,%.15g font \"%s,%d\" 
%s rotate by %f %s;\n",
                     undo_string_escapes (label), units, lpos(1),
                     lpos(2), lpos(3), f, s, halign, angle, colorspec);
          else
            fprintf (plot_stream,
!                    "set label \"%s\" at %s %.15g,%.15g font \"%s,%d\" %s 
rotate by %f %s;\n",
                     undo_string_escapes (label), units,
                     lpos(1), lpos(2), f, s, halign, angle, colorspec);
          endif
--- 930,941 ----
  
          if (nd == 3)
            fprintf (plot_stream,
!                    "set label \"%s\" at %s %.9g,%.9g,%.9g font \"%s,%d\" %s 
rotate by %f %s;\n",
                     undo_string_escapes (label), units, lpos(1),
                     lpos(2), lpos(3), f, s, halign, angle, colorspec);
          else
            fprintf (plot_stream,
!                    "set label \"%s\" at %s %.9g,%.9g font \"%s,%d\" %s rotate 
by %f %s;\n",
                     undo_string_escapes (label), units,
                     lpos(1), lpos(2), f, s, halign, angle, colorspec);
          endif

reply via email to

[Prev in Thread] Current Thread [Next in Thread]