I want to add axes around a picture with TikZ as shown in the following image. I think I can handle positioning the axes, but how can I set them to have this kind of look, rather than being just usual axes ?
Thank you for your advices
I want to add axes around a picture with TikZ as shown in the following image. I think I can handle positioning the axes, but how can I set them to have this kind of look, rather than being just usual axes ?
Thank you for your advices
You could use pgfplots to draw the axes and include the image with \addplot graphics.
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\pgfplotsset{compat = 1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = left,
axis line style = -,
axis line shift = 2mm,
every tick/.append style = {black, thin},
tick align = outside,
unit markings = parenthesis,
xlabel = {$x$},
x unit = {m},
ylabel = {$y$},
y unit = {m}
]
\addplot graphics [
xmin = 0,
xmax = 4,
ymin = -2,
ymax = 2
]
{example-image-a};
\end{axis}
\end{tikzpicture}
\end{document}
1.6 is indeed a bit old - no special reason for that. I updated the version to 1.18 now.
– luki
Jan 05 '22 at 21:41
Here is a basic setup you can adjust to your needs.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[font=\sffamily]
\fill (0,-2) rectangle (4,2);
\begin{scope}[yshift=-2mm]
\draw (0,-2) --node[yshift=-9mm]{$\mathsf{x(m)}$} (4,-2);
\foreach \x in {0,...,4}{\draw (\x,-2)--(\x,-2.2) node[below]{\x};}
\end{scope}
\begin{scope}[xshift=-2mm]
\draw (0,-2) --node[yshift=9mm, sloped]{$\mathsf{y(m)}$} (0,2);
\foreach \y in {-2,...,2}{\draw (0,\y)--(-.2,\y) node[left]{\y};}
\end{scope}
\end{tikzpicture}
\end{document}
\documentclass{...}and ending with\end{document}. – SebGlav Jan 05 '22 at 16:16pgfplots? If the latter, perhaps https://tex.stackexchange.com/questions/155194/tufte-like-axis-with-pgfplots? – Torbjørn T. Jan 05 '22 at 16:29