[Tex/LaTex] Reverse graphics in pgfplots

MATLABmatlab2tikzpgfplots

Issue and Question

I encountered that my graphics are all upside down. Now I have to mirror them in pgfplots. How can I perform this step?

It is no solution using the option [y dir=reverse] which also turns the axis label upside down (MWE):

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[y dir=reverse]
    \addplot graphics {GraphicsFile.png};
\end{axis}
\end{tikzpicture}
\end{document}

Appearance

This issue appeared due to the usage of matlab2tikz where in MATLAB. I performed the following command to correct the orientation.

set(gca,'Ydir','normal');

Now that I applied all changes/adaptations to my figures I do not want to go back. But maybe you could also give a short answer about improving my usage of MATLAB.

Best Answer

To flip your graphic, you can pass options to the plot graphics/node to scale the node vertically by -1 and change its default anchor point:

Sample output

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.9}

\begin{document}

\begin{tikzpicture}
  \begin{axis}
    \addplot[plot graphics/node/.append style={yscale=-1,anchor=north west}] 
      graphics[xmin=0,xmax=2,ymin=0,ymax=2] {example-image-a};
  \end{axis}
\end{tikzpicture}

\end{document}

By default the node has anchor at south west.

Generally one can pass \includegraphics options to the via

\addplot graphics[includegraphics={options}] {image-file};

but no combination of the includegraphics options does a reverse of orientation, so we have to pass the options to the node instead.