Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I try to plot data in pgfplots. My data file has 1001 points in a range (x axis) from 2499999500 to 2500000500, so I have steps of 1. I get the message “Package pgfplots Warning: Axis range for axis x is approximately empty; enlarging it (it is [2499999500.0000000:2500000500.0000000]) ...” in the log file and a straight line is drawn, the axis limits range from 2e9 to 3e9, overriding them with xmin = ... etc. does not help. Any idea what can be done?

File test.tex:

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
      \begin{axis}[
        xmin=2499999500,
        xmax=2500000500,
      ]
      \addplot+ table [x index=0, y index=1] {testdata.dat};
    \end{axis}
\end{tikzpicture}

\end{document}

File testdata.dat:

2499999500 0
2500000000 1
2500000500 0
share|improve this question
    
This requires at least 9 digits of precision for the x-values. I think this is beyond the precision of the underlying math code. As your x-axis labels would be quite long anyway I would suggest subtracting a constant. I can plot the data easily with something like table[x expr=\thisrow{x}-2500000000] and add a note in the x axis label or something similar. –  Alexander Apr 18 '13 at 10:29
    
@Alexander oh I just spent some time figuring that out then I noticed you'd put the answer here. I won't post my answer in that case, I suggest you post this as an answer since I can confirm independently that it works:-) –  David Carlisle Apr 18 '13 at 11:15
    
Hm, that works for the little example above, but if I insert real data (1001 points, too big to post here) I get another rounding issue: several steps. You could test it by generating a test file with a spreadsheet program, the numbers from 2499999500 to 2500000500 in the first column and a ramp (1, 2, 3, ...) in the second. –  Chris Apr 18 '13 at 12:41
add comment

1 Answer

Not quite an answer but a workaround is using an expression such as:

\addplot+ table [x expr=\thisrow{x}-2500000000] {\mytable};

to subtract a large common number from the dataset. This still uses the math engine of pgf and works for your small test case.

\documentclass[border=1mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepackage{filecontents}
\begin{filecontents}{testdata.dat}
2499999500 0
2500000000 1
2500000500 0
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}[xtick=data, xticklabels from table={testdata.dat}{[index]0}]
  \addplot+ table [x expr=\thisrowno{0}-2500000000] {testdata.dat};
\end{axis}
\end{tikzpicture}
\end{document} 

enter image description here

For closely spaced data this still breaks down. The precision of the FPU engine can be shown with

\pgfkeys{/pgf/fpu=true}
\pgfmathparse{2500000400 - 2500000500}
\pgfmathprintnumber{\pgfmathresult}
\pgfkeys{/pgf/fpu=false} 

Which prints zero as the change occurs at the 8th digit. So I would recommend using either gnuplot as suggested in the pgfmanual or preprocessing the dataset externally.

Alternatively the fp package is more suited to the problem as it operates with fixed point. I do not know how to integrate it with pgfplots.


Update:

Whereas with LaTeX the precision is limited it is not a problem to use LuaTeX for the calculation here and the results are quite nice. If run with LuaTeX the following example produces the correct output:

\documentclass[tikz,preview]{standalone}
\usepackage{tikz,pgfplots,pgfplotstable}
\pgfplotsset{compat=1.8} 

\begin{document}

\pgfplotstableread
{
x y 
2499999500  1
2499999501  2
2499999502  3
2499999503  4
2499999504  5
2499999505  6
2499999506  7
2499999507  8
2499999508  9
2499999509  10
}\mytable;

\begin{tikzpicture}
    \begin{axis}
    \addplot+ table [x expr=\directlua{tex.print(\thisrow{x}-2499999500)},y=y] {\mytable}; 
    \end{axis}
\end{tikzpicture}

\end{document}

New example with lua

share|improve this answer
    
I added a MWE and a picture to your answer. I hope you don't mind. –  Luigi Apr 18 '13 at 17:38
    
@Luigi: Thank you for the MWE. I guess the real answer would involve using a math engine with more precision. Maybe pgf can use lua for that in the future. –  Alexander Apr 18 '13 at 18:07
2  
You can use x expr=\directlua{tex.print(\thisrowno{0}-2500000000)} in order to evaluate your expression using lualatex. It has higher precision. –  Christian Feuersänger Apr 20 '13 at 11:02
    
@ChristianFeuersänger: Thank you for the hint, I feared that it would be tricky but this is works nicely and without large modifications. –  Alexander Apr 20 '13 at 11:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.