# Criteria for deciding how best to specify coordinates with tikzpicture with or without pgfplots

Conclusion

The original question, as Christian has pointed out, was far too broad and basically a result of being overwhelmed by the size of two main manuals for tikz and pgfplots and how they related to each other. The tikzpicture is the main environment for creating graphics and so you should make a study of the Specifying Coordinates section of pgfmanual.pdf. The current version of tikz is 2.10. The following is good if you're just starting out: Minimal Introduction To Tikz

If you're including a pgfplot in your tikzpicture then section 4.16 of pgfplots.pdf should be studied and in particular 4.16.1 explaining the axis cs coordinate system. The current manual is version 1.8 and the current version of pgfplots is 1.9.

I have left my original MWEs below to show what I was trying to do that solicited all the advice below. The first example has become redundant because I now know how to do curves in 3D with \addplot3 and that example is now rewritten entirely within a \begin{axis} environment. See Positioning various types of node over a 3D Plot. None the less, the idea of placing tikzpicture elements over an imported graphic background is still very important as you will want to use graphics that can't possibly be created totally within, such as a photo of an aeroplane upon which you're placing design descriptions.

The second example was about finding the most convenient way to place a LaTeX node over a pgfplot. This is where percusse pointed out axis cs and Jake pointed out you can scale the axis rather than the whole tikzpicture. Handling scaling when you have an imported background is still an open question for me. Scaling the background can get it out of step with what you've placed over it and I'm still not sure what is the best way to manage it.

One irony is that the node at facility that I was initially having trouble with and was looking for an alternative, is now very useful to me. I just had to realise what it was actually doing and now I'm making good use of it. It's all part of the learning curve.

I was also using my own axis labels to deal with problems that were caused by using an outdated pgfplots. These problems have been fixed in version 1.8.

Thanks to all who have commented.

MWE 1 Output

MWE 1 Imported Image

MWE 1 Code

\documentclass[12pt,a4paper,fleqn]{article}
\usepackage[a5paper,margin=14mm]{geometry}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{pgfplots}
\usepackage{mathtools}

\def\dd{\,{\rm d}}
\def\nv{\mathbf{n}}

\begin{document}
%
\par\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0)
{\includegraphics[width=0.6\textwidth]{orient}};
\begin{scope}
[x={(image.south east)},y={(image.north west)}]
\path node at (.14, .03) {$x$} node at (.96, .49) {$y$}
node at (0.35, .95) {$z$} node at (.65, .03) {$\dd r$}
node at (.96, .17) {$\nv = (0, 1, 0)$} node at (0.65, 0.65) {$\dd s$};
\end{scope}
\end{tikzpicture}
%
\par\begin{tikzpicture}[scale=3]
\node[anchor=south west,inner sep=0] (image) at (0,0)
{\includegraphics[width=0.4\textwidth]{orient}};
\begin{scope}
[x={(image.south east)},y={(image.north west)},font=\footnotesize]
\path node at (.14, .03) {$x$} node at (.96, .49) {$y$}
node at (0.35, .95) {$z$} node at (.65, .03) {$\dd r$}
node at (.96, .17) {$\nv = (0, 1, 0)$} node at (0.65, 0.65) {$\dd s$};
\end{scope}
\end{tikzpicture}
%
\end{document}


MWE 2 Output

MWE 2 Code

\documentclass[10pt,a4paper,fleqn]{article}
\usepackage[a5paper,margin=14mm]{geometry}
\usepackage{pgfplots}
\usepackage{amsmath}

\begin{document}
%
\par\begin{tikzpicture}[scale=1.00]
%
\begin{axis}[
xtick={-1, 1, 3}, ytick={-8,-4, 4,8},
width=12cm, height=5cm,
axis lines=middle,
enlargelimits=true,
samples=201,
clip=false
]
\path node [xshift=9.2cm][yshift=1.1cm] {$t$}
node [xshift=2.0cm][yshift=3cm] {$y$};
\addplot [thick, color=green, domain=-1:0] ( {x}, {0} );
\addplot [thick, color=green, domain=0:4] ( {x}, {x^2*(2-x)*(4-x)^2} )
node [color=green, pos=.55][yshift=-1.8cm]
{$g(t)=\begin{cases} 0&-1\le t \le 0\\t^2(2-t)(4-t)^2&\hfill 0\le t \le4 \end{cases}$};
%
\end{axis}
%
\end{tikzpicture}
%
\end{document}

-
Do you mean the node placement with cases? You can place it as a standalone node with \node (<node name if required>) at (axis cs:<x axis coord>,<y axis coord>) {...}; wrt to the axis itself. –  percusse Oct 17 '13 at 8:44
If you scale your axis using \begin{axis}[scale=...] instead of \begin{tikzpicture}[scale=..., the "proper" label placement works. About your main question: I'm not entirely sure what issue you're encountering. Could you give an example of things that need adjustment when you scale the axis? And could you clarifiy what is meant by "placing everything without tedious amounts of trial and error"? –  Jake Oct 17 '13 at 8:59
@percusse Your suggestion is at least direct and more appropriate than what I was doing. I've got vs 1.8 of pgfplots.pdf and vs 2.10 of pgfmanual.pdf They're huge and very difficult to search for things like \node, axis and cs. What's pgf and what's tikz gets a bit blurred. I can't find your specific suggestion in either of them although there are elements of it. Any suggestions? Cheers –  Geoff Pointer Oct 17 '13 at 10:37
@Jake I'm fully committed to LaTeX but I miss being able to just drag objects to where I want them. I find trying to locate various bits and pieces of a tikzpicture a bit tedious sometimes. My first attempts to put coordinates in, that seem right, usually end up badly placed and I have to mess around with them several times. For example in my MWE, [pos=.55][yshift=-1.8cm] didn't just fall out, I had to tweeze it around until it sat right. Even percusse's suggestion took me several tries before it sat right. –  Geoff Pointer Oct 17 '13 at 10:43
I have a macro \whereami which will convert relative into absolute units. See elfsoft2000.com/projects/cheap.pdf –  John Kormylo Oct 20 '13 at 15:41

I admit that I am still a little bit unsure of what a "good" answer would be. It sounds as if you are overwhelmed by two huge manuals, and you are struggling to find the information you look for.

On the other hand, the question is quite imprecise as "please explain all the different ways ... " cries for "give me a (usable) manual".

I believe that a good answer to your question is to assist you as much as possible with finding the correct sections in the manual, and then let you come up with more specific questions.

First, let me point out one aspect which addressed your problem at hand (I believe it has been addressed to some extend in the comments to your question, but anyway): You wrote TikZ code to generate axis labels by means of

\path node [xshift=9.2cm][yshift=1.1cm] {$t$}
node [xshift=2.0cm][yshift=3cm] {$y$};


As you pointed out correctly, this will suffer from any change to width/height of the figure (unless you scale everything). However, this piece of code is to generate a description of an axis - and there is builting and preconfigured support for this task: simply use xlabel and ylabel in the axis to generate them, i.e.

\begin{axis}[
xtick={-1, 1, 3}, ytick={-8,-4, 4,8},
width=12cm, height=5cm,
axis lines=middle,
enlargelimits=true,
samples=201,
clip=false,
xlabel=$t$,
ylabel=$y$,
]


In order to get correct placement, you should consider writing \pgfplotsset{compat=1.8} into the document's preamble (as you surely did already).

Note that the generated labels are almost what you had manually, except that the default pgfplots style places the xlabel over the x axis to avoid overlaps with tick labels.

Regarding the desire to get a good overview over the coordinate placement routines in conjunction with pgfplots and tikz, I would recommend the following sections of http://pgfplots.sourceforge.net/pgfplots.pdf :

1. section "Axis Descriptions" contains a complete overview over the various ways to place axis descriptions, either absolute or relative, either respecting tick label widths or not, even shifts along "outer normals" are supported. This stuff blends seamlessly into TikZ's coordinate placement mechanisms; but all the provided coordinate systems are only valid inside of a pgfplots axis. I suppose this answers lots of questions.

EDIT 1.1 Section "Custom Annotations" explains how to place any kind of nodes, especially based on absolute coordinates. It also covers scatter plots with nodes near coords and the placements of nodes on fractions using pos.

1. section "Alignment Options" shows how to place & align an axis, so it appears to be a very localised chapter. However, it summaries the way TikZ places and aligns nodes briefly (namely by means of anchor and at), so it might be of interest.

2. section "TikZ Interoperability" is very special and should only be read if it is really needed. It is needed if a pgfplots axis and the data coordinates should much those of the TikZ x and y vectors 1:1. This is rarely needed, but your application might fit here.

Aside from these recommendations, the TikZ manual contains "all different ways of specifying coordinates" in its section "Specifying Coordinates" with regards to TikZ alone. I understand that you'd like to have a "scalable" coordinate placement. This, in turn, might benefit a lot if you work with x=<x unit>, y=<y unit> and write (4,3) or something like that. Scaling these units is easy: simply modify <x unit> and <y unit>.

I hope this gets you started and back to productive progress. This will certainly lead to specific questions like "how can I get the following without an xshift" which can be addressed on this site.

-