3

Can you help me in correctly positioning labels to an existing empty plot using tikz ?

My problems are:

  • my labels are too far from the axes;
  • my labels are not centered.

Here is the empty plot

enter image description here

and here is what I currently do to superimpose axis labels:

\documentclass[a4paper, 11pt]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern} 
\usepackage{amsmath, amssymb}
\usepackage{tikz}

\begin{document}

\begin{figure} \centering
\begin{tikzpicture}
\node (plot) {\includegraphics[scale=0.7]{plot.pdf}};
\node at (plot.west) {$y$};
\node at (plot.south) {$x$};
\end{tikzpicture}
\caption{My graphic.}
\end{figure}

\end{document}

enter image description here


  • 2
    The easiest way for this particular problem would be \node at ([xshift=1cm]plot.west) {$y$}; and \node at ([yshift=1cm]plot.south) {$x$}; where you will replace 1cm with needed distance. But I'd suggest to draw the complete graphic with pgfplots. You will find a lot of examples and help here. – Ignasi Jun 4 '13 at 12:25
2

I am guessing that the labels are too far away because the pdf file contains a lot of white space around the graph. You can use the trim option of \includegraphics to effectively trim that unwanted white space, like so :

\documentclass[a4paper, 11pt]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern} 
\usepackage{amsmath, amssymb}
\usepackage{tikz}

\begin{document}

\begin{figure} \centering
\begin{tikzpicture}
    \node (plot) {\includegraphics[scale=0.7, trim=1cm 1cm 0 0]{plot.pdf}};
    \node at (plot.west) {$y$};
    \node at (plot.south) {$x$};
\end{tikzpicture}
\caption{My graphic.}
\end{figure}

\end{document}

where in trim=l b r t, l, b, r and t correspond to left, bottom, right and top respectively. Hopefully, this would also solve the centering problem.

|improve this answer|||||
  • Looks nice! I did not know the trim option. Let me try and I will probably accept your answer very soon. – Marco Jun 4 '13 at 13:07

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.