In answering PGFPlots: How to draw a label at a zero of a function?, I got stuck on converting a length in pt
to the actual coordinate value in the axis cs
system.
Here I only need the x
value, but my question is how does one obtain the actual x
/y
values of a coordinate once you have their physical location.
Sub-Question:
- Why does the circle not get drawn for the intersection on the left once I use
\pgfextra
?
Notes:
- Physical coordinate locations can be extracted as per Extract x, y coordinate of an arbitrary point in TikZ.
Code:
\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{intersections}
% https://tex.stackexchange.com/questions/33703/extract-x-y-coordinate-of-an-arbitrary-point-in-tikz
\newdimen\XCoord
\newdimen\YCoord
\newcommand*{\ExtractCoordinate}[1]{\path (#1); \pgfgetlastxy{\XCoord}{\YCoord};}%
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=middle,
axis y line=middle,
domain=-4:7,
xmax=7,
]
\addplot[no marks,blue,thick, name path global=My Graph] {x*x-4*x-7};
\addplot[no marks,draw=none, name path global=x Axis ] {0};
\fill[red,name intersections={of=My Graph and x Axis,total=\t}]
\foreach \s in {1,...,\t}{
\pgfextra{\ExtractCoordinate{intersection-\s}}
(intersection-\s) circle (2pt)
node [above] {$\XCoord$}
};
\end{axis}
\end{tikzpicture}
\end{document}