I tried the solution proposed in : How can/should I include annotated images?

However, the coordinates don't match with the coordinates I used when plotting the diagrams (data coordinates). For example, I have a mesh generated by a python program and matplotlib and I want to annotate it, using the same coordinates I used when plotting the data.

Let's say there is a node in the mesh at coordinates (2,3). I'd like to be able to annotate it using \node at (2,3) {text};

  • 2
    This can be done very conveniently using PGFplots. Could you include a sample image in your question? – Jake May 2 '12 at 11:30
  • @Jake I tried to use the python package matplotlib2tikz, which produces a pgfplots plot. The result is fine, but the coordinates still seem scaled. pastebin.com/W6dyawE4 This is the output created by the package. At the bottom, I'm creating two nodes which don't show up at the specified coordinates. Any idea? – triggerfish May 2 '12 at 12:13
  • 1
    Related (for including an image and referring to its coordinate system): Image with axis – Jake May 2 '12 at 12:24

If you want to refer to the axis coordinates of a pgfplots axis, you'll need to put the TikZ commands (like \draw, \node, or \path) inside the axis environment, and you'll need to use the axis cs: coordinate system.

In your example, you could say

\addplot [red, mark=*, mark options={draw=black}, only marks]
coordinates {

\node at (axis cs:1,1) [anchor=north east] {test};
\node at (axis cs:0,0) [anchor=south west] {test};

to get

| improve this answer | |
  • Awesome, this works like a charm. You might wonder why I need plotting at all, as these meshes could be created using simple \draw and \fill commands. However, these meshes can get really complicated. Maybe I will implement another backend for my python program to just create \fill and \draw commands. For now, this solution is perfect though. – triggerfish May 2 '12 at 12:24
  • @triggerfish: Glad it helps! Would you mind editing your question and question title to more accurately reflect what the question turned out to be about (something like "Annotating a pgfplots graph", since you're not actually using an external PDF)? – Jake May 2 '12 at 12:30
  • @Jake I'm a bit "lost in search": I've got my data points and axes correctly labeled; I'd just want to add R² = 0.61 "somewhere" in the plot; how best to do that? – nutty about natty May 16 '13 at 8:02

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.