8

I have a Delaunay-triangulated surface generated in MATLAB, which I would prefer to render in tikz. I use Nico Schlömer's matlab2tikz script to generate the standalone tex file.

The MATLAB result looks like this:

matlab out

When I compile the standalone .tex file generated by matlab2tikz, however, it looks like this:

matlab2tikz

In the MATLAB image, the data aspect ratio is set with MATLAB's daspect command, like so:

daspect([1000 1000 1])

I have tried to accomplish the same thing using unit vector ratio in pgfplots. However, it makes no difference how I set it. In every case, I get this error:

! Dimension too large.
<to be read again> 
\relax 
l.7398 \end{axis}

Any one of these pgfplots settings will cause the error:

unit vector ratio 1 1 1
unit vector ratio 1 1
unit vector ratio 1000 1000 1
unit vector ratio 1 1 0.001

or any of the above with *

and also, for the sake of experiment (I don't want a 1 1 1 ratio, it will just give me a flat surface):

axis equal
axis equal image

The plot box ratio approach from here doesn't work either - same error.

I figure it must be possible to make this work. The tikz rendering looks very nice otherwise. The data set has about 7000 lines, so I can't post it here, and anyway it works without the unit vector transformation, so I don't think that the data is the problem.

Here is the code for the axis (with the large colormap omitted!):

\begin{axis}[%
%width=6.82222222222222in,
%height=3.40720720720721in,
area legend,
unit vector ratio = 1 1,
view={-37.5}{30},
scale only axis,
xmin=545550,
xmax=584400,
xlabel={Ost [m]},
xmajorgrids,
ymin=5542050,
ymax=5569500,
ylabel={Nord [m]},
ymajorgrids,
zmin=8.46471544296322,
zmax=16.9194594285807,
zlabel={$\text{U [ms}^{\text{-1}}\text{]}$},
zmajorgrids,
axis x line*=bottom,
axis y line*=left,
axis z line*=left

The complete source may be obtained here.

  • @Qrrbrbirlbel actually, compat=newest... is that the problem? – Stephen Bosch Sep 18 '13 at 14:48
  • what happens when you use unit vector ratio 2 2 1 – percusse Sep 18 '13 at 14:56
  • 2
    You can use z post scale=0.1 to reduce the z axis length to one tenth of its default length. Unfortunately, this approach doesn't allow you to specify the ratio of the axis lengths explicitly, though. In any case, you should note that you want the unit vector lengths for x and y to be much shorter than for z (so you should be trying things like unit vector ratio=1 1 1000 instead of unit vector ratio=1000 1000 1) – Jake Sep 18 '13 at 15:09
  • @percusse unit vector ratio 2 2 1 gives the same error. – Stephen Bosch Sep 18 '13 at 15:17
  • 1
    @StephenBosch: That might be a good idea – Jake Sep 18 '13 at 15:29
6

You could work around the problem by providing the x, y and z unit vectors explicitly yourself:

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}

\begin{axis}[%
area legend,
xlabel={Ost [m]},
xmajorgrids,
ylabel={Nord [m]},
x={(0.0001cm,0.00005cm)}, y={(-0.0001cm,0.00005cm)}, z={(0cm,0.2cm)},
ymajorgrids,
zmin=8.46471544296322,
zmax=16.9194594285807,
zlabel={$\text{U [ms}^{\text{-1}}\text{]}$},
zmajorgrids,
axis lines*=left,
colormap/violet
]

\addplot3[patch,forget plot]  table[point meta=\thisrow{c}]{data.dat};

\end{axis}

\end{tikzpicture}

\end{document}
  • I hadn't thought of that. As long as the absolute values of the components of the unit vectors for x and y are the same, I should get equal scaling. I see you didn't bother with my huge colormap ;) – Stephen Bosch Sep 18 '13 at 16:29
4

I have found a more satisfying solution to the problem, and it makes use of plot box ratio after all. It turns out that you cannot use the values from daspect to set the plot ratio: they are too large.

So which values do you use?

The current axis object in MATLAB gives the answer. With the figure to be exported current (either by invoking figure(<figurehandle>) or clicking the figure), get the axis handle. The attribute PlotBoxAspectRatio is functionally equivalent to plot box ratio. You need this value before invoking matlab2tikz. Here is the MATLAB code:

a1 = gca;
plotBoxAspect = get(a1,'PlotBoxAspectRatio');
plotBoxStr = sprintf('plot box ratio = %d %d %d',plotBoxAspect(1),plotBoxAspect(2),plotBoxAspect(3));
matlab2tikz('outputfile.tex','standalone',true,'extraAxisOptions',plotBoxStr);

The result is about as close to the original MATLAB surface plot as you can reasonably expect:

pgfplots corrected

Using this method, there is no need to manually set the unit vectors.

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.