I need to add axes to a bunch of figures in my document, I'm trying with tikz but maybe there's an easier and more elegant way to do it (looking at you, overpic)? The result I'm trying to achieve is not like this, I need the axes to have the arrows as well.

I got some MWE working, but the axes are vertically misaligned (they should be outside of the picture). I've tryed adding \vspaces but they don't seem to work as I'd like.

MWE:

\documentclass{scrreprt}
\usepackage{subfig}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\begin{figure}[h!]
\vspace{-0.6cm}
\centering
\subfloat[]{%
\begin{tikzpicture}
\draw [->] (0,0) -- (0.5,0) node[right]{\footnotesize$$y$$};
\draw [->] (0,0) -- (0,0.5) node[above]{\footnotesize$$x$$};
\end{tikzpicture}
\hspace{-1cm}
\includegraphics[width=0.45\textwidth,height=1cm]{example-image-a}}
\subfloat[]{%
\begin{tikzpicture}
\draw [->] (0,0) -- (0.5,0) node[right]{\footnotesize$$y$$};
\draw [->] (0,0) -- (0,0.5) node[above]{\footnotesize$$x$$};
\end{tikzpicture}
\hspace{-1cm}
\includegraphics[width=0.45\textwidth,height=1cm]{example-image-a}}
\\
\subfloat[]{%
\includegraphics[width=0.45\textwidth,height=1cm]{example-image-a}}
\hspace{-0.9cm}
\begin{tikzpicture}
\draw [->] (0,0) -- (-0.5,0) node[left]{\footnotesize$$y$$};
\draw [->] (0,0) -- (0,0.5) node[above]{\footnotesize$$x$$};
\end{tikzpicture}
\subfloat[]{%
\includegraphics[width=0.45\textwidth,height=1cm]{example-image-a}
\hspace{-0.9cm}
\begin{tikzpicture}
\draw [->] (0,0) -- (-0.5,0) node[left]{\footnotesize$$y$$};
\draw [->] (0,0) -- (0,0.5) node[above]{\footnotesize$$x$$};
\end{tikzpicture}}
\caption{Foo}
\end{figure}
\end{document}


EDIT I would like the axes to be something like this:

If you don't want to use the heavy tikz weapons, picture mode is sufficient to draw a few arrows:

\documentclass{scrreprt}
\usepackage{subfig}
\usepackage{graphicx}
%\usepackage{tikz}
\begin{document}
\begin{figure}[htbp]
\vspace{-0.6cm}
\centering
\subfloat[]{%
\setlength{\unitlength}{\textwidth}
\begin{picture}(.45,0.1)
\put(0,0){\includegraphics[width=0.45\textwidth,height=1cm]{example-image-a}}
\put(.46,-.01){\vector(-1,0){.07}}
\put(.46,-.01){\vector(0,1){.05}}
\put(.453,.045){x}
\put(.373,-.014){y}
\end{picture}
}
\caption{Foo}
\end{figure}
\end{document}


Second approach with the heavy tikz weapons:

\documentclass{scrreprt}
\usepackage{subfig}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\begin{figure}[htbp]
\vspace{-0.6cm}
\centering
\subfloat[]{%
\begin{tikzpicture}
\node (image) at (0,0) {\includegraphics[width=0.45\textwidth,height=1cm]{example-image-a}};
\draw [->] (image.south west) -- ++(0.5,0) node[right]{\footnotesize\textit{y}};
\draw [->] (image.south west) -- ++(0,0.5) node[above]{\footnotesize\textit{x}};
\end{tikzpicture}
}
\end{figure}
\end{document}


Off-topic: I would not use [h!] as floating specifier, this is almost always a guarantee for bad image placement

• I need the axes to be lower, both outside of the picture – Superuser27 Mar 19 at 10:16
• @Superuser27 You can move the arrows wherever you want – user36296 Mar 19 at 10:18
• @Superuser27 Can you make a sketch where you want your axis to be? – user36296 Mar 19 at 10:24
• So for the labels (\put(.545,.07){x} \put(.46,.007){y}) I just have to try around with the numbers until they are in the right position? Is there no easier way to position them relative to the picture maybe? Or just add labels to the vectors like with tikz? – Superuser27 Mar 19 at 10:24
• @Superuser27 Sure, you can change the inner sep. For example \begin{tikzpicture}[inner sep=10pt] – user36296 Mar 20 at 17:27

Maybe like this?

\documentclass{article}
\begin{document}
<<test,echo=F,fig.cap="Axis with background image and more.">>=
library(png)
plot(1:2, type='n', xlab="x", ylab="y",xlim=c(0,10),ylim=c(0,7.5),axes=F)
lim <- par()
u <- par("usr")
rasterImage(ima, u[1]+.5, u[3]+.5, u[2]-.5, u[4]-.5)
arrows(u[1], u[3], u[2], u[3], code = 2, xpd = TRUE)
arrows(u[1], u[3], u[1], u[4], code = 2, xpd = TRUE)
lines(c(1, 1.2, 1.35,4.5, 6, 8.3, 9.5), c(.6, 1.3, 0.9,2.7, 0.6, 4.7, 7.0), lwd=5, col="blue")
@
\end{document}


Of course, this need R and knitr to be compiled.

If you need only a little axis:

\documentclass{article}
\begin{document}
<<test,echo=F,fig.cap="Axis with background image and more.">>=
library(png)
plot(1:2, type='n', xlab="", ylab="",xlim=c(0,10),ylim=c(0,7.5),axes=F)
lim <- par()
u <- par("usr")
rasterImage(ima, u[1]+.5, u[3]+.5, u[2]-.5, u[4]-.5)
arrows(u[1], u[3], u[2]/3, u[3], code = 2, xpd = TRUE)
arrows(u[1], u[3], u[1], u[4]/3, code = 2, xpd = TRUE)
axis(1, at=u[2]/6, tck=0, labels="x")
axis(2, at=u[4]/6, tck=0, labels="y")
lines(c(1, 1.2, 1.35,4.5, 6, 8.3, 9.5), c(.6, 1.3, 0.9,2.7, 0.6, 4.7, 7.0), lwd=5, col="blue")
@
\end{document}

• What code is this? :D never seen it... Actually I don't need to plot anything on the figure, I just need the axes. – Superuser27 Mar 19 at 13:01
• @Superuser27 It is R code embedded in a LateX file (.Rnw) , that knitr (a R package) export to a true/pure LateX file (.tex) that can be compiled as usual . With R (free) and RStudio editor (free) installed, all the process is simply push the "Compile PDF" button. With respect to the unwanted blue line, simply remove the row lines(c(1, .... – Fran Mar 19 at 13:17