0

I have a .csv file plotted and a vertical line at a specific x value. I found the intersection point and now I need to get its x and y values that correspond to actual plot values and not tikz coordinates. This is my code, I found the two custom commands on the internet and while they seem to work, they don't work as I want them to. Can anyone help me modify those commands to return the real value?

\usepackage{pgfplots}
\usepackage{tikz}
    \usetikzlibrary{arrows,shapes,calc,positioning,intersections}

\begin{document}

\makeatletter
\newcommand\xcoord[2][center]{{%
    \pgfpointanchor{#2}{#1}%
    \pgfmathparse{\pgf@x/\pgf@xx}%
    \pgfmathprintnumber{\pgfmathresult}%
}}
\newcommand\ycoord[2][center]{{%
    \pgfpointanchor{#2}{#1}%
    \pgfmathparse{\pgf@y/\pgf@yy}%
    \pgfmathprintnumber{\pgfmathresult}%
}}
\makeatother


\begin{tikzpicture}
    \begin{axis} [ width=\textwidth,height=7cm,cycle list name=black white,ymode=normal,xmode=log,grid=both,xlabel=$Hz$,ylabel=$V/\sqrt{Hz}$]
        \addplot[name path global=n] table [x=freq (Hz), y=V / sqrt(Hz), col sep=comma] {data.csv};
        \addplot[thick,sharp plot,update limits=false, name path global=h]coordinates {(1000,-2e-6) (1000,1.3e-5)};
        \fill [name intersections={of=n and h,by={intersection1}}] (intersection1) circle[radius=2.5pt];
        \node [above right] at (intersection1) {(\xcoord{intersection1},\ycoord{intersection1}) $1.167uV/\sqrt{Hz}$};
        \legend{Voltage Noise Density}
    \end{axis}
\end{tikzpicture}

\end{document}

And here is the data.csv

freq (Hz),V / sqrt(Hz)
10.00,11.42E-6
13.80,9.718E-6
19.05,8.272E-6
26.30,7.041E-6
36.31,5.994E-6
50.12,5.103E-6
69.18,4.344E-6
95.50,3.699E-6
131.8,3.150E-6
182.0,2.683E-6
251.2,2.286E-6
346.7,1.949E-6
478.6,1.662E-6
660.7,1.418E-6
912.0,1.211E-6
1.259E3,1.036E-6
1.738E3,888.1E-9
2.399E3,763.0E-9
3.311E3,657.6E-9
4.571E3,569.2E-9
6.310E3,495.5E-9
8.710E3,434.2E-9
12.02E3,383.9E-9
16.60E3,342.8E-9
22.91E3,309.6E-9
31.62E3,283.2E-9
43.65E3,262.4E-9
60.26E3,246.2E-9
83.18E3,233.9E-9
114.8E3,224.6E-9
158.5E3,217.7E-9
218.8E3,212.9E-9
302.0E3,209.9E-9
416.9E3,208.7E-9
575.4E3,209.7E-9
794.3E3,214.2E-9
1.096E6,224.7E-9
1.514E6,245.2E-9
2.089E6,268.5E-9
2.884E6,216.4E-9
3.981E6,109.9E-9
5.495E6,51.88E-9
7.586E6,25.49E-9
10.47E6,13.03E-9
14.45E6,6.933E-9
19.95E6,3.898E-9
27.54E6,2.346E-9
38.02E6,1.502E-9
52.48E6,1.006E-9
72.44E6,693.4E-12
100.0E6,487.5E-12

The result is this:

enter image description here

But in the parenthesis I want it to display (1000,0.1167).

The weird thing is that when I specified the coordinates of the vertical line I wrote the actual values and not relative tikz coordinates. So why can't it just return something similar?

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. – TobiBS Aug 25 '20 at 12:44

Browse other questions tagged or ask your own question.