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:




      \addplot+ table [x index=0, y index=1] {testdata.dat};


File testdata.dat:

2499999500 0
2500000000 1
2500000500 0
  • 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

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.

2499999500 0
2500000000 1
2500000500 0

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

enter image description here

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

\pgfmathparse{2500000400 - 2500000500}

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.


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:



x y 
2499999500  1
2499999501  2
2499999502  3
2499999503  4
2499999504  5
2499999505  6
2499999506  7
2499999507  8
2499999508  9
2499999509  10

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


New example with lua

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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