8

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.

2
  • 1
    Setting matlab up to produce the correct orientation in the first place, as in the final part of your question, is probably the best approach. – Andrew Swann Jan 29 '14 at 9:05
  • But I guess that there must be a way to do that as with default \includegraphics, I can perform \scalebox{1}[-1]{\includegraphics{GraphicsFile.png}}. Somehow it should be performed to somewhat like \addplot graphics[xmin=0,xmax=1,ymin=0,ymax=1]{\scalebox{1}[-1]{\includegraphics{GraphicsFile.png}}. – strpeter Jan 29 '14 at 13:54
7

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.

2
  • Brilliant, as I thought there exists an "intrinsic way" to do it but I did not think of yscale, which would had been obvious after my comment above. Thank you! Nevertheless \scalebox is not an argument of \includegraphics but your last statement is nice to know. – strpeter Jan 29 '14 at 20:20
  • @strpeter Good. In the last comment, I was partly thinking of the scale option of \includegraphics which is less powerful than \scalebox. – Andrew Swann Jan 30 '14 at 13:05

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.