Re: High precision negative numbers in pgfplots

View: New views
2 Messages — Rating Filter:   Alert me  

Re: High precision negative numbers in pgfplots

by Christian Feuersaenger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Paul,

The problem is caused because of the very small (relative) y range: division by this range essentially leads to a number which is beyond TeX's capacities. This has not yet been fixed because the required /relative/ precision is (currently) beyond the arithmetics capabilities: the first 4 digits of each input coordinate will be LOST when they are used in a plot and the arithmetics only has 4-6 significant digits.

The only solution which is directly available is a data transformation which maps the data into an interval where the range is larger (relative to the values of ymin and ymax).

In other words: add 27.90 to every coordinate and undo this transformation before showing tick labels.

Pgfplots can do that automatically using

\begin{tikzpicture}
        \begin{axis}[
                y coord trafo/.code=    {\pgfmathparse{#1+27.9}\message{trafo(#1) = \pgfmathresult.    }},
                y coord inv trafo/.code={\pgfmathparse{#1-27.9}\message{invtrafo(#1) = \pgfmathresult.    }},
                yticklabel style={/pgf/number format/precision=5},
                scaled y ticks=false,
        ]
        \addplot table {P.dat};
        \end{axis}
\end{tikzpicture}


The 'y coord trafo' maps the input y coordinate to 'y + 27.9'. The inverse trafo simply undos this addition.  The yticklabel styles increases the *displayed* tick label precision and the 'scaled y ticks=false' is a necessity to avoid tick scaling here.


However: the relative precision may drop below acceptable thresholds! The '\message' commands issue output in your log file. Check if that is acceptable and discard the '\message' commands afterwards.


I hope this helps for the present problem (without too much inconvenience).

Regards

Christian

----------------
Original message posted add pgf-users follows:

Date: Mon, 14 Sep 2009 15:20:58 +0100
From: Paul Weaver <ch3pjw@...>
Subject: [Pgf-users] High precision negative numbers in pgfplots
To: pgf-users@...
Message-ID: <200909141520.58965.ch3pjw@...>
Content-Type: text/plain;  charset="us-ascii"

Hopefully this is the right place to ask about pgfplots, as well as pgf/tikz!

I'm trying to plot the following data table using pgfplots:

id  energy
0   -27.902726901
1   -27.896452902
2   -27.903331903
3   -27.901764904
4   -27.901853905
5   -27.901901906
6   -27.901827907

but when I compile my latex I get the following error twice:

myfile.ltx:35:Dimension too large. \end{axis}

The resulting plot looks fine, but the errors are frustrating! I can get rid
of the error if I lower the precision of the numbers below an acceptable
level, or if I _remove the negative sign_ from the numbers! I can't think of
a good way to fix this...

I'm using pgfplots version 1.2.2.

Thanks!


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users

Parent Message unknown Re: High precision negative numbers in pgfplots

by Christian Feuersaenger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Paul,

I have been thinking over your problem and I was wondering because the
internal transformations in pgfplots should have caught this problem
automatically.

And: I found a bug! I am very grateful for your mail, because I wouldn't
have found it otherwise :-)

I should have read your mail more carefully, the clue was: for
*positive* sign, the algorithm works correctly, but the check for
negative signs was missing.

This has been fixed now such that your example compiles fine without any
errors, and without the provided extra transformation.

Best regards

Christian

Paul Weaver schrieb:

> Hi Christian,
>
> Thanks so much for this! It works like a charm as far as I can see. I was
> wondering about how to manipulate the tick marks in that manner after reading
> the pgfplots manual, but it was alas beyond me :)
>
> Regards,
> Paul Weaver
>
> On Tuesday 22 September 2009 18:54 you wrote:
>  
>> Hello Paul,
>>
>> The problem is caused because of the very small (relative) y range:
>> division by this range essentially leads to a number which is beyond TeX's
>> capacities. This has not yet been fixed because the required /relative/
>> precision is (currently) beyond the arithmetics capabilities: the first 4
>> digits of each input coordinate will be LOST when they are used in a plot
>> and the arithmetics only has 4-6 significant digits.
>>
>> The only solution which is directly available is a data transformation
>> which maps the data into an interval where the range is larger (relative to
>> the values of ymin and ymax).
>>
>> In other words: add 27.90 to every coordinate and undo this transformation
>> before showing tick labels.
>>
>> Pgfplots can do that automatically using
>>
>> \begin{tikzpicture}
>> \begin{axis}[
>> y coord trafo/.code=    {\pgfmathparse{#1+27.9}\message{trafo(#1) =
>> \pgfmathresult.    }}, y coord inv
>> trafo/.code={\pgfmathparse{#1-27.9}\message{invtrafo(#1) = \pgfmathresult.
>>   }}, yticklabel style={/pgf/number format/precision=5},
>> scaled y ticks=false,
>> ]
>> \addplot table {P.dat};
>> \end{axis}
>> \end{tikzpicture}
>>
>>
>> The 'y coord trafo' maps the input y coordinate to 'y + 27.9'. The inverse
>> trafo simply undos this addition.  The yticklabel styles increases the
>> *displayed* tick label precision and the 'scaled y ticks=false' is a
>> necessity to avoid tick scaling here.
>>
>>
>> However: the relative precision may drop below acceptable thresholds! The
>> '\message' commands issue output in your log file. Check if that is
>> acceptable and discard the '\message' commands afterwards.
>>
>>
>> I hope this helps for the present problem (without too much inconvenience).
>>
>> Regards
>>
>> Christian
>>
>> ----------------
>> Original message posted add pgf-users follows:
>>
>> Date: Mon, 14 Sep 2009 15:20:58 +0100
>> From: Paul Weaver <ch3pjw@...>
>> Subject: [Pgf-users] High precision negative numbers in pgfplots
>> To: pgf-users@...
>> Message-ID: <200909141520.58965.ch3pjw@...>
>> Content-Type: text/plain;  charset="us-ascii"
>>
>> Hopefully this is the right place to ask about pgfplots, as well as
>> pgf/tikz!
>>
>> I'm trying to plot the following data table using pgfplots:
>>
>> id  energy
>> 0   -27.902726901
>> 1   -27.896452902
>> 2   -27.903331903
>> 3   -27.901764904
>> 4   -27.901853905
>> 5   -27.901901906
>> 6   -27.901827907
>>
>> but when I compile my latex I get the following error twice:
>>
>> myfile.ltx:35:Dimension too large. \end{axis}
>>
>> The resulting plot looks fine, but the errors are frustrating! I can get
>> rid of the error if I lower the precision of the numbers below an
>> acceptable level, or if I _remove the negative sign_ from the numbers! I
>> can't think of a good way to fix this...
>>
>> I'm using pgfplots version 1.2.2.
>>
>> Thanks!
>>    
>
>
>
>  


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users