[Tex/LaTex] Arrow tip center with TikZ (and pgfplots)

pgfplotstikz-pgf

The arrow default behaviour is shown on the left picture part. How can I achieve that the “circle” arrow tips (see the picture below) end at their center, as drawn in the right image, but without manual tweaking?

If it is important: I need it to mark beginning and end of a curve in pgfplots, but I missed this feature so many times in TikZ as well that I post the more general question.

Arrow behaviour: state of the art and what I need.

\documentclass[tikz,border=5mm,convert]{standalone}

\usetikzlibrary{arrows}

\begin{document}

\begin{tikzpicture}
\draw [black!20] (-.2,-.2) grid (1.2,1.2);
\draw [<->] (0,0) -- (1,1);
\draw [o-*] (0,1) -- (1,0);
\begin{scope}[xshift=1.5cm]
  \draw [black!20] (-.2,-.2) grid (1.2,1.2);
  \draw [<->] (0,0) -- (1,1);
  \draw [o-*] (-.06,1.06) -- (1.06,-.06);
\end{scope}
\end{tikzpicture}

\end{document}

Ignasi posted a solution that works with pgfplots as well (thanks for that) but it does not integrate in the arrows “system” and lengths have to be given manually. Is there a solution that provides these features?


Using the solution with pgfplots results in strange looking graphs if there are
plot coordinates inside the arrow tip:

Strange looking plot

I consider this being a feature but a different behaviour could be beneficial. So, is there a possibility to automatically skip coordinates inside the arrow tip? Using a fill for the ring is no solution since it will remove other objects as well. Here the code for the plot:

\documentclass[tikz,convert]{standalone}

\usetikzlibrary{arrows.meta}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}[markstart/.style={{Circle[open, length=4mm]}-,shorten <=-2mm}]
\begin{axis}[width=5cm]
\addplot [markstart] coordinates { (0,0) (0.01,0) (0.01,0.01) (0.04,0.03) (.5,.5) };
\end{axis}
\end{tikzpicture}

\end{document}

Best Answer

If new (TiKZ 3.0) arrows.meta library is used, tip length can be fixed and with shorten help, arrows circle centers can be moved to point where you want:

\documentclass[tikz,border=5mm,convert]{standalone}

\usetikzlibrary{arrows.meta}

\begin{document}

\begin{tikzpicture}
\draw [black!20] (-.2,-.2) grid (1.2,1.2);
\draw [<->] (0,0) -- (1,1);
\draw [{Circle[open]}-{Circle}] (0,1) -- (1,0);
\begin{scope}[xshift=1.5cm]
  \draw [black!20] (-.2,-.2) grid (1.2,1.2);
  \draw [<->] (0,0) -- (1,1);
  \draw [{Circle[open, length=1mm]}-{Circle[length=2mm]}, shorten >=-1mm, shorten <=-.5mm] (0,1) -- (1,0);
\end{scope}
\end{tikzpicture}

\end{document}

enter image description here

I supose there exists some variable which defines tip length and can be used to automatically compute shorten length, but I don't know it.

Update

If just want to mark start and ending point in a pgfplots curve, instead of tips and arrows can use pgfplots mark or just circle nodes as you said in your comments or is used in How to mark/label nth data point from file in pgfplots?

Unless you fill circle or marks internal lines will be shown (as in next figure). If you know how many coordinates are used to draw the curve, you can use mark repeat to draw a curve with marks just at start and end points.

\documentclass[tikz,border=5mm,convert]{standalone}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}[markstart/.style={{Circle[open, length=4mm] .}-,shorten <=-2mm}]
\begin{axis}[width=5cm]
\addplot [mark=none] coordinates { (0,0) (0.01,0) (0.01,0.01) (0.04,0.03) (.5,.5) } node[circle, minimum size=2pt,inner sep=0pt,draw,pos=0]{} node[circle, minimum size=2pt,inner sep=0pt,draw,pos=1]{};

\addplot [mark=o, mark repeat=4] coordinates { (0,0.4) (0.01,0.39) (0.01,0.35) (0.04,0.32) (.5,.0) };
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here