2

I export plots using matlab2tikz and pgfplots from MATLAB to TeX. Most of my plots contain "serial date numbers", which are the days since January 0, 0000. As you can guess, the numbers get quite high, and the difference between the data points is relatively small.

The following sample raises a "Dimension too large" error. However, I already could compile some similar figures, for example like this one.

My MWE is the following:

\documentclass{scrartcl}

\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}

\begin{figure}
\centering
\input{example.tikz}
\end{figure}

\end{document}

with the stripped contents of example.tikz being the following:

% This file was created by matlab2tikz v0.4.7 running on MATLAB 8.3.
% Copyright (c) 2008--2014, Nico Schlömer <nico.schloemer@gmail.com>
% All rights reserved.
% Minimal pgfplots version: 1.3
% 
% The latest updates can be retrieved from
%   http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz
% where you can also make suggestions and rate matlab2tikz.
% 
\begin{tikzpicture}

\begin{axis}[%
width=15cm,
height=10cm,
scale only axis,
xmin=735784.472,
xmax=735784.6382,
xtick={735784.5,735784.5625,735784.625},
xticklabels={{04.06. 12:00:00},{04.06. 13:30:00},{04.06 15:00:00}},
ymin=-0.15,
ymax=3.5
]
\addplot [color=red,only marks,mark=x,mark options={solid},forget plot]
  table[row sep=crcr]{%
735784.472210648    0\\
735784.563194444    3.09\\
735784.6125 0.54\\
735784.638194444    0\\
};
\addplot [color=blue,solid,forget plot]
  table[row sep=crcr]{%
735784.474305556    0\\
735784.522222222    2.92188333278572\\
735784.578472222    3.08013114814648\\
735784.635416667    0\\
};
\end{axis}
\end{tikzpicture}%

I already tried restrict x to domain without any success.

2

The reason for this is because of the big numbers but small differences at some point internal calculations exceed the dimension limit in TeX. A possible solution is to transform the coordinates to a smaller domain. This can be achieved by adding

\pgfplotsset{x coord trafo/.code={\pgfmathparse{#1-735784.4}\pgfmathresult}}

where the last number has to be adapted to your case. Somehow, this still only works after deleting the x limits and ticks, with the resulting example.tikz being:

% This file was created by matlab2tikz v0.4.7 running on MATLAB 8.3.
% Copyright (c) 2008--2014, Nico Schlömer <nico.schloemer@gmail.com>
% All rights reserved.
% Minimal pgfplots version: 1.3
% 
% The latest updates can be retrieved from
%   http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz
% where you can also make suggestions and rate matlab2tikz.
% 
\begin{tikzpicture}
\pgfplotsset{
x coord trafo/.code={\pgfmathparse{#1-735784.4}\pgfmathresult}}

\begin{axis}[%
width=15cm,
height=10cm,
scale only axis,
ymin=-0.15,
ymax=3.5
]
\addplot [color=red,only marks,mark=x,mark options={solid},forget plot]
  table[row sep=crcr]{%
735784.472210648    0\\
735784.563194444    3.09\\
735784.6125 0.54\\
735784.638194444    0\\
};
\addplot [color=blue,solid,forget plot]
  table[row sep=crcr]{%
735784.474305556    0\\
735784.522222222    2.92188333278572\\
735784.578472222    3.08013114814648\\
735784.635416667    0\\
};
\end{axis}
\end{tikzpicture}%

Still, it would be nice to transform the limits and ticks as well. If you know how, feel free to add it!

enter image description here

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.