1

I am trying to achieve something very similar what is discussed here.

I have the following image, and I know the size of the box. West to East (366, 534), South to North (0.00565, 10.6) and the last direction (page normal) is (0, 19.9).

sample_image

MWE

\documentclass[]{standalone}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[3d 
box,xmin=0,xmax=10,ymin=366,ymax=534,
%grid=both,
minor z tick num=1]
\addplot3 graphics[points={%
  ( 0,366,0.00565) => (0, 227)
  (19.9,534,0.00565) => (3804,0)
  ( 0,534,0.00565) => (3951,227)
  ( 0,366,-10.6) => (47,432)
}] {mwe.png};

\end{axis}
\end{tikzpicture}

\end{document}

My code is producing,

enter image description here

At the linked discussion there is a matlab script to get coordinates correctly, and I am thinking that's the part where I am messing up things, as I try to get the pixels using gimp.

Are there any other robust way to get the pixels rather than a Matlab script?

Or is it my perspective can not be handled via pgfplots? I also admit that I am not quite sure if I am using good group of points to map coordinates into the pixels.

trblnc
  • 451
  • 2
    I don't think this method is realistic in pgfplots with any other perspective than a simple projection. Yet your picture seems to be one-point-perspective. Can you not generate the graphics so it is a simple projection ? – marsupilam Jun 29 '17 at 10:02
  • 1
    Aaa, really :( I generate them via Paraview, I think I can do differently. However I had this one-point-perspective to keep the figures minimal horizontally. Also, here it is mentioned that orthogonal 3d projection should work by the developer. – trblnc Jun 29 '17 at 10:58

2 Answers2

3

As @marsupilam mentioned [it is also in the documentation (my bad) of pgfplots]: perspective projection is unsupported by pgfplots (version 1.15).

Luckily, one can enable so called parallel projection in Paraview to export images similar to following one, that I believe fits in the requirements of pgfplots.

parallel_view

And the size of box for both of the images is; West to East (366, 534), South to North (0.00565, 10.6) and the last direction (page normal) is (0, 19.9).

Note: I repeat the warning given in the documentation here again. If you use GIMP to get the coordinates, pay attention to that GIMP consider top-left as (0,0), but PGFPLOTS bottom-left.

MWE

\documentclass[]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[3d box,
ymin=0,ymax=19.9,
zmin=0.00565,zmax=10.6,
%minor z tick num=1]
\addplot3 graphics[points={%
  (366, 0,   0.00565) => (156, 0)
  (366, 19.9,0.00565) => (0, 478-166)
  (534, 0,   0.00565) => (3399,0)
  (366, 0,   10.6) => (239,478-313)
}]{mwe_parallel.png};

\addplot3+ [only marks] coordinates {
  (366, 0,   0.00565) 
  (366, 19.9,0.00565)
  (534, 0,   0.00565)
  (366, 0,   10.6)
};
\end{axis}
\end{tikzpicture}
\end{document}

Ant the result;

good_result

UPDATE: Use width or similar option in axis to scale the png. It handles the issue in @marsupilam's comment. See more on scales.

Scaled results will look like that(also with updated colors);

enter image description here

trblnc
  • 451
  • You should add the options ultra thick,axis on top, and probably lighten the color tones or (use \addplot[opacity=.7]) in your picture, because the 3d of the axis is really hard to read (even gives me migraine !) – marsupilam Jun 29 '17 at 16:02
  • Thanks, I agree it is hard to read. I tried ticklabel style = {font=\huge}, in axis options but did work as good as I hoped. – trblnc Jun 30 '17 at 05:33
  • @marsupilam do you know why the default text size is too small for the tick labels in my result? – trblnc Jun 30 '17 at 11:42
  • they're not that small, it's just your picture that is big ! You can use \documentclass[12pt,tikz]{standalone} (defaults to 10pt) or scale your pic down... – marsupilam Jun 30 '17 at 11:46
0

Here, have some goofy colored debugging,

The output

enter image description here

The code

\documentclass[tikz]{standalone}
\usetikzlibrary{backgrounds}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}

\begin{document}

\begin{tikzpicture}
  \begin{axis}
    [
      name=myPlot,
      ymin=0,ymax=19.9,
      zmin=0.00565,zmax=10.6,
      minor z tick num=1,
      xtick distance=20,
      ultra thick,
      axis on top,
      3d box=complete,
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      xscale=.4, % I think this setting is what you need   %%
      yscale=.9, %                                         %%
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    ]
    \addplot3 
    [opacity=.8,]
    graphics
    [
      points=
      {%
        (366, 0,   0.00565) => (156, 0)
        (366, 19.9,0.00565) => (0, 478-166)
        (534, 0,   0.00565) => (3399,0)
        (366, 0,   10.6) => (239,478-313)
      },
    ]
    {mweParallel.jpg};

    \addplot3+ [only marks] coordinates 
    {
      (366, 0,   0.00565) 
      (366, 19.9,0.00565)
      (534, 0,   0.00565)
      (366, 0,   10.6)
    };

    \pgfplotsextra
    {
      \foreach \x in {0,1}
      {
        \foreach \y in {0,1}
        {
          \foreach \z in {0,1}
          {
            \coordinate (a-\x-\y-\z) at (rel axis cs:\x,\y,\z);
          }
        }
      }
    }
  \end{axis}
  \foreach \i in {0,1}
  {
    \foreach \j in {0,1}
    {
      \draw [orange, line width=1mm] (a-\i-\j-0) -- (a-\i-\j-1);
      \draw [yellow, line width=1mm] (a-\i-0-\j) -- (a-\i-1-\j);
      \draw [green!80!black, line width=1mm] (a-0-\i-\j) -- (a-1-\i-\j);
    }
    \fill [opacity=.3,green!80!black,] (a-\i-0-0) -- (a-\i-1-0) -- (a-\i-1-1) -- (a-\i-0-1) ;
    \fill [opacity=.3,yellow,] (a-0-\i-0) -- (a-1-\i-0) -- (a-1-\i-1) -- (a-0-\i-1) ;
    %\fill [opacity=.3,orange,] (a-0-0-\i) -- (a-1-0-\i) -- (a-1-1-\i) -- (a-0-1-\i) ;
  }

\end{tikzpicture}
\end{document}
marsupilam
  • 6,383