I want to include an external graphics with pgfplots. I tried to follow the instructions of the manual (p45 et seq.) as carefully as possible. But the result is hoorible as hell.

Here is the code I am using:

axis on top=true,
grid=both,minor tick num=1,
\addplot3 graphics[
points={%difference of canvas y coord. because pgfplots counts from the lower left.
(353,754.7,196) => (2,1192-944)
(356,757,198) => (476,1192-153)
(353,758.5,198) => (188,1192-1)
(356,753.3,196) => (242,1192-1192)
 }] {Example.png};

And here is the graphics I try to include:

graphics to be included

Here is the same graphics in which I marked in orange the 3D-coordinates and below in black the canvas coordinates (which I read out via paint). graphics with marked coordinates

And here is the same graphics in a box (made with Mathematica) to show that I read out the coordinates correctly and to give an impression of the dimensions and the orientation: Graphics with coordinate system

And here is the screenshot of the odd result:


I guess I am doing something wrong. But I cannot find my mistake. Can somebody of you give me a hint?

  • I am guessing it has something to do with different axes scaling differently.
    – mythealias
    Oct 23 '12 at 23:32
  • Thanks for the feedback. I tried to change with e.g. z post scale=2 etc. the axis scaling, but nothing works. The funny thing is: If I make a 3D plot just of my points, I get almost what I want. But I still cannot manage it for my desired plot. Do you or others can give a bit more help?
    – partial81
    Oct 24 '12 at 6:42
  • 1
    I can reproduce the problem, but I do not know what happens. I recomputed the canvas coords with gimp (they have been completely different, but the result looks the same). I added the debug key to \addplot graphics[ debug and inspected the file: the matrix looks ok. I solved the system with octave (it has full rank) and it also results in the wrong output. The result receives a skewed z vector! It seems like a rotated hyperplane, is that right? I am wondering if that can make a difference... did you try to use some other coordinate which is not on the hyperplane (like your red dot)? Oct 24 '12 at 10:28
  • Thanks @Christian: I guess you get other coordinates because the size changed a bit after uploading. Yes, the figure is a part of a cone. I plotted one more graphics so that one can see that I read out the coordinates correctly (I multiply x,y by 10^9,z by 10^6). If I follow you advice and use the red dot, I get a good result! One can check this by using my first pic of my post and the coordinates (353,754.7,196)=>(46,517-393),(356,757,198)=>(254,517-94),(353,758.5,198)=>(121,517-0),(354.5,753.3,198)=> (73,517-95) instead of the original (356,753.3,196)=>(156,517-515). Well, it works! But why?
    – partial81
    Oct 24 '12 at 17:43
  • 2
    @partial81 I think it could be a projection issue. By the way, your projection is perspective (not parallel) and pgfplots supports only the second, at the moment.
    – Luigi
    Oct 24 '12 at 18:03

PGFPlots requires four linearly independent points: they must not share the same hyperplane.

I think that Luigi found the clue why it produced a result at all: your image has been generated with a perspective projection. Consequently, the four provided vectors are linearly independent - but they are still from a hyperplane.

I would bet that if you have a parallel projection (aka orthogonal projection), PGFPlots would refuse to accept the points because the linear system will be underdetermined.

If only three of your points are on the hyperplane and one is outside of it, you satisfy the requirements and the linear system is well-defined.

  • Thank you Christian and thank you @Luigi for solving my problem and giving a detailed answer! In future I will chose only three points to be on my hyperplane and the forth to be somewhere else. P.S.: Just a general remark: Thank you Christian for your wonderful TikZ and pgfplots! I could not work without them! Herzlichen Dank!
    – partial81
    Oct 24 '12 at 20:44
  • Thanks for the praise! Concerning TikZ, I want to stress that the main praise goes to Till Tantau and Mark Wibrow. I only contributed small sub-components of TikZ. Oct 25 '12 at 7:43

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.