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:


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> 
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!):

area legend,
unit vector ratio = 1 1,
scale only axis,
xlabel={Ost [m]},
ylabel={Nord [m]},
zlabel={$\text{U [ms}^{\text{-1}}\text{]}$},
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? Commented Sep 18, 2013 at 14:48
  • what happens when you use unit vector ratio 2 2 1
    – percusse
    Commented Sep 18, 2013 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
    Commented Sep 18, 2013 at 15:09
  • @percusse unit vector ratio 2 2 1 gives the same error. Commented Sep 18, 2013 at 15:17
  • 1
    @StephenBosch: That might be a good idea
    – Jake
    Commented Sep 18, 2013 at 15:29

2 Answers 2


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



area legend,
xlabel={Ost [m]},
ylabel={Nord [m]},
x={(0.0001cm,0.00005cm)}, y={(-0.0001cm,0.00005cm)}, z={(0cm,0.2cm)},
zlabel={$\text{U [ms}^{\text{-1}}\text{]}$},
axis lines*=left,

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



  • 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 ;) Commented Sep 18, 2013 at 16:29

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));

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .