I am trying to load an eps file generated with an external software into a TikZ picture and draw a coordinate system around it, such that I can superimpose additional data.
This post (Drawing on an image with TikZ) was extremely useful, but I'm still struggling to adjust the code for my purposes.
I prepared a small example to illustrate the problem. The file b.eps contains a plot of the function f(x)=x over the interval [-5:5].
I then try to plot the same function in TikZ such that the two curves overlap.
\documentclass{standalone}
\usepackage{pgfplots,tikz}
\begin{document}
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0)
{\includegraphics[width=8cm]{b.eps}};
\begin{scope}[shift={(image.south west)},%
x={(image.south east)},%
y={(image.north west)}]
\begin{axis}[xmin=-5, xmax=5, %
ymin=-5, ymax=5, %
xlabel = $x$, ylabel = $y$] %
\draw[green, dashed, thick] (axis cs: -5,-5) -- (axis cs: 5,5);
\end{axis}
\end{scope}
\end{tikzpicture}
\end{document}
The problem seems to be that the axis-environment does not have the correct width and height, which is why the blue line and the dashed green line don't overlap.
I tried to extract the width and height of the scope and pass it on to the arguments of the axis environment, but all my attempts failed. Any advice on how to achieve that would be highly appreciated.
pgfplots
manual is useful here. I think you want to set theaxes equal
option totrue
; it isfalse
by default.node
for the image, it would be better if you used\addplot graphics
. See tex.stackexchange.com/questions/38632/image-with-axisb.eps
that you posted doesn't run from -5 to 5, but something like -5.2 to 5.2 in x and -5.6 to 5.6 in y. In order to properly register the image, you need to figure out the exact limits when you're generating the image.