# pgfplots "dimension too large" with 3D graphic from external source

I want to include a 3D plot that I created in R. The plot is prepared according to the example given for Matlab in the pgfplots manual. I cropped the whitespace around the saved png, added transparency and wrote down the coordinates of selected points (green) in GIMP. I also converted the y-axis value because GIMP has the origin in the upper left and pgfplots in the lower right.

However, I get

! Dimension too large.


as an error.

The relevant code is here

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
xmin=0,
xmax=0.05,
ymin=0,
ymax=0.05,
zmin=0,
zmax=2.3e-5
]
points={(0.045,0.01,1e-6) => (169,506-460)
(0.045,0.045,1e-6) => (399,506-410)
(0.01,0.01,2e-5) => (85,506-83)
(0.01,0.025,2e-5) => (185,506-69)}
] {Rplot};
\end{axis}
\end{tikzpicture}
\end{document}


The original plot from R looks like this

and the GIMP version like this

For those who like to play around, I uploaded the picture here:

What am I doing wrong? Did I select the wrong points or are the axis values too small?

EDIT:

I have invesitgated a bit more and actually found that I had to define the corner points and not just any point. Maybe I misread the documentation there. so now I have defined the origin 0,0,0, the top left corner of the graphic, the bottem left and right corner of the graphic

\addplot3[] graphics[
points={
(0,0,0) => (15,525-300)
(0,0,2.2e-5) => (1,525-60)
(0.05,0,0) => (135,525-525)
(0.05,0.05,0) => (554,525-436)
%(0,0.02,2.2e-5) => (283,525-19)
}
] {Rplot08};


But still the axis box now seems distorted. The left shows the pgfplots version, the right the R version, printed together in one document.

I am close to give up on this issue und include the plots from R directly although I do not like the font really

• From your pictures it looks as if all points are correct but the one at (0.05,0.05,0). Are you sure that the z-value of that coordinate is zero? Jun 7 '13 at 16:35
• Yes it is zero as you can see in the R plot on the right. if you set enlargelimits=false the plots look more alike. I started thinkink now if the problem has to do with perspective and orthogonal view... Jun 7 '13 at 16:51
• Yes, that is also possible. At least the lines along the axis are not parallel in your png-file. Jun 7 '13 at 16:56

The initial selection of points violates the expectations of the \addplot3 graphics command: they are on a plane (try to draw a plane through all four of them).

Numerically, this means that the underlying linear system has rank 6 although it is an 8x8 matrix. This can be seen by adding debug:

\addplot3[] graphics[debug, ...

which generates the file Rplot.dat containing the view matrix induced by your points. According to the debug output, the matrix is

canvasmapmatrix=[4.5e-2 0.0e0 1.0e-2 0.0e0 1.0e-6 0.0e0 1.0e0 0.0e0
0.0e0 4.5e-2 0.0e0 1.0e-2 0.0e0 1.0e-6 0.0e0 1.0e0
4.5e-2 0.0e0 4.5e-2 0.0e0 1.0e-6 0.0e0 1.0e0 0.0e0
0.0e0 4.5e-2 0.0e0 4.5e-2 0.0e0 1.0e-6 0.0e0 1.0e0
1.0e-2 0.0e0 1.0e-2 0.0e0 2.0e-5 0.0e0 1.0e0 0.0e0
0.0e0 1.0e-2 0.0e0 1.0e-2 0.0e0 2.0e-5 0.0e0 1.0e0
1.0e-2 0.0e0 2.5e-2 0.0e0 2.0e-5 0.0e0 1.0e0 0.0e0
0.0e0 1.0e-2 0.0e0 2.5e-2 0.0e0 2.0e-5 0.0e0 1.0e0
];


you can copy-paste this output into octave and type

octave:3> rank(canvasmapmatrix )
ans =  6
octave:4> size(canvasmapmatrix )
ans =
8   8


It is a pity that pgfplots was not smart enough to complain properly; that should probably become more robust.

This explains your initial question (the "dimension too large"). In addition, pgfplots requires the graphics to be orthographic. More precisely, it needs three unit vectors x, y, and z. Support for perspective projections is an open feature request. This explains why it looks different compared to your R figure.

• In a few months it can be smarter (I hope) :) Jun 10 '13 at 19:38