Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have tried to import external 3D plots from Matlab et.al, but to no avail. To show what I managed to accomplish, I present a minimum non-working example below. Any ideas of what I'm doing wrong?

Cheers, Stefanos

Makefile:

all: 3dtest.pdf

3dtest.pdf: 3dtest.tex bumps.png
    latexmk -pdflatex="xelatex -shell-escape " -pdf 3dtest.tex

bumps.png: bumps.m
    matlab -nodesktop -nosplash -r "bumps;exit"
    sleep 1
    reset
    convert bumps.png -trim +repage -transparent white bumps.png

bumps.m (don't bother running this with Octave, saving the surface plot is for some reason incredibly slow, and the result isn't very good):

function bumps()
  figure(1)
  [X,T]=meshgrid(linspace(0,1,400),linspace(0,2,400));
  c=[3 2 5 4];
  surf(X,T,abs(sin(c(1)*pi*X).*exp(1j*c(2)*pi*T)+sin(c(3)*pi*X).*exp(1j*c(4)*pi*T)))
  shading interp
  colormap(jet(1000))
  axis off
  setPapersize(6*[4 3])
  print -dpng bumps
end

function setPapersize(papersize)
  set (gcf,'papertype', '<custom>')
  set (gcf, 'papersize', papersize)
  set (gcf, 'paperposition', [0 0 papersize])
end

3dtest.tex:

\documentclass{standalone}
\usepackage{tikz,pgfplots}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[width=10cm]
    \addplot3 graphics[points={
      (0,0,0) => (1212,0)
      (1,0,0) => (2791,428)
      (0,2,0) => (0,557)
      (0.8872,2,1.854) => (1398,2064)
      (1,2,2)
    }] {bumps};
  \end{axis}
\end{tikzpicture}

\end{document}

The resultant image:

Image

EDIT: Original image:

Image

FYI, I'm on Texlive 2012, using XeLaTeX (as seen in the Makefile).

share|improve this question
    
How did you determine the mapping of the points to the pixels of the image? Could you upload the image? –  Jake Aug 7 '12 at 20:15
    
Just as specified in the manual, measuring from the lower left corner in Gimp. The first three 3D coordinates are trivial, and the last one was checked in Matlab. –  Stefanos Carlström Aug 8 '12 at 4:15
    
It works fine for me. What version of PGFPlots are you using? –  Jake Aug 8 '12 at 7:12
    
@Jake: The default one that's delivered with Texlive 2012, i.e. 1.5.1, which also seems to be the last released one, albeit released in December. You didn't have to change anything? –  Stefanos Carlström Aug 8 '12 at 18:14
    
I have now also tried the latest Git revision, and inserted the following, as suggested by Pgfplots during compilation: \pgfplotsset{compat=1.6}. No difference. –  Stefanos Carlström Aug 8 '12 at 19:46
show 3 more comments

2 Answers

I found that it works on my system with both TL 2011 and TL 2012 and with both pdflatex and xelatex -- provided I use the .png version of the image. xelatex failed to compile with .jpg (which is the format of the graphics in the question); pdflatex worked everytime.

My guess is that something is wrong with the installation on your system; although I could not find what according to your .log files (send by private email).

share|improve this answer
    
Sorry for not answering earlier, I've been on holidays. I will try this out pronto. –  Stefanos Carlström Sep 2 '12 at 12:53
    
Well, it depends on what you mean with "manage to compile the expression". I definitely get an image included, but approximately a factor five larger than the axis object. While researching the bb file solution (which I could not get to work by the way), I found out that the bb in the dvipdfm format differed from that in the dvipdfmx format, by a factor of 2/3. By scaling the coordinates manually, I got the plot to fit, but with a factor 0.4825. I have not been able to succeed with any of {PDF,Xe,Lua}LaTeX, I did not see any difference. Cheers, –  Stefanos Carlström Sep 2 '12 at 13:42
    
Thanks for the experiment. I have the impression that your result is different from mine (I believe mine did not even compile in xelatex). I can offer more detailed advice (hopefully a bugfix) if we continue the discussion per mail (my address is listed on top of the pgfplots manual). –  Christian Feuersänger Sep 2 '12 at 17:21
add comment

the same without MatLab. Run with xelatex or latex->dvips->ps2pdf

\documentclass[pstricks]{standalone}
\usepackage{pst-solides3d}
\begin{document}

\psset{Decran=60,viewpoint=20 70 15 rtp2xyz}
\begin{pspicture}(-7,-5)(5.5,6.5)
\psSurface[ngrid=0.02 0.02,linewidth=0.2pt,axesboxed,algebraic,
   grid=true,showAxes=false,
   tablez=0 0.1 2 { } for, zcolor=0.5 1 1 0.03 1 1 (hsb), 
   Zmin=0,Zmax=2](0,0)(2,4)%
 {sqrt((sin(3*Pi*x/2)*cos(2*Pi*y/2)+sin(5*Pi*x/2)*cos(4*Pi*y/2))^2+
        (sin(3*Pi*x/2)*sin(2*Pi*y/2)+sin(5*Pi*x/2)*sin(4*Pi*y/2))^2 )}
\end{pspicture}

\end{document}

enter image description here

share|improve this answer
    
Thanks for the effort, but the main reason I want to use external graphics, is the need to include high resolution data (compilation slow or nigh impossible, if done in LaTeX). –  Stefanos Carlström Sep 9 '12 at 8:29
    
that image is not created inside LaTeX, it is done by PostScript when running dvips –  Herbert Sep 9 '12 at 8:40
    
Sorry, should have read more carefully. Will try that. EDIT: Having trouble finding out how to specify numerical data (i.e. list of data points). –  Stefanos Carlström Sep 9 '12 at 9:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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