1

I received some plots that were generated in Mathematica such as this one:

https://i.stack.imgur.com/WW8ww.jpg

I would like to insert them using something like:

\begin{center}
\large{\emph{\textbf{My Plot}}}\\
\includegraphics[scale=1]{mypotentials.png}
\end{center}

And I would like to add some x labels and y labels to them. What is a really nice way to do this? Using TikZ to generate new plots is out of the question.

Everywhere else I was looking at was adding more than just the label.

I'm looking for something simple like

ylabel= V(r), or \psi_{2}(r)

xlabel = r 
Kvo
  • 331
  • 1
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Also please fix the link to your image as it is not working. – Martin Schröder Nov 29 '15 at 23:25
  • psfrag cross my mind (if you have eps picture). or stacked small picture over yours with showing direction of the axes. – Zarko Nov 29 '15 at 23:40
  • Nothing simple like that will work because TeX has no idea what is in the picture so no idea that it even contains axes, let alone where. However, you can add the labels without too much difficult either with an overlaid TikZ picture, for example. See http://tex.stackexchange.com/questions/9559/drawing-on-an-image-with-tikz for ways to do this and note that several answers there are mutually supportive. – cfr Nov 30 '15 at 01:35

1 Answers1

3

You can overlay anything on top of a picture, but you will need to do a lot of manual placement. Here I use relative coordinates from TikZ so that changing the size of the image will not affect the placement.

\documentclass[border=1pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{mwe}
\begin{document}
\begin{tikzpicture}
  \node[inner sep=0pt] (A) {\includegraphics{example-image}};
  \node[red] (B) at ($(A.south)!.05!(A.north)$) {x label};
  \node[red,rotate=90] (C) at ($(A.west)!.05!(A.east)$) {y label};
  \node[red] at ({$(A.west)!.4!(A.east)$} |- {$(A.south)!.8!(A.north)$}) {demo};
\end{tikzpicture}
\end{document}

overlay image


Here is an alternative using a savebox to compute the width and height.

\documentclass[border=1pt]{standalone}
\usepackage{tikz}
\usepackage{mwe}
\begin{document}
\begin{tikzpicture}
  \sbox0{\includegraphics{example-image}}% get width and height
  \node[above right,inner sep=0pt] at (0,0)  {\usebox{0}};
  \node[red] at (0.5\wd0,0.05\ht0) {x label};
  \node[red,rotate=90] at (0.05\wd0,0.5\ht0) {y label};
  \node[red] at (.4\wd0, .8\ht0) {demo};
\end{tikzpicture}
\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • I think the method in the threads I linked to is a bit more intuitive because you can just specify coordinates as fractions of the image. Surely easier than doing the calculations directly each time. Not to say this won't work, obviously. Just it seems like more hassle. – cfr Dec 01 '15 at 02:13