1

I need to add horizontal lines (asymptotes) to a plot made from a csv file, with the y-axis value taken from this last. I found an example to draw the horizontal lines

\addplot [thick,black]
table[x=freq,y=mod2,col sep=space] {file.csv};
\coordinate (A) at (axis cs:0,-74.927351816709300);
\coordinate (O1) at (rel axis cs:0,0);
\coordinate (O2) at (rel axis cs:1,0);              
\draw [red,sharp plot,dashed] (A -| O1) -- (A -| O2);

but I have to add the specific value -74.927351816709300 and -87.967485127488640 manually. How can I read it automatically form csv file? The resulting figure should be as follow

enter image description here

Maybe there is a better solution (tell me!) but anyway the need to extract a value from a csv file remains. Following the compilable code (there are redundant packages)

\documentclass[12pt,a4paper,twoside,openright]{book}

\usepackage[english]{babel}
\usepackage[babel]{csquotes}
\usepackage[style=numeric-comp,useprefix,hyperref,backend=bibtex,indexing]{biblatex}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb}
\usepackage[english]{varioref}
\usepackage{booktabs}
\usepackage{indentfirst}
\usepackage{floatflt}
%\usepackage{subfigure}
\usepackage{rotating}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage[small,normal,bf]{caption}
\usepackage[binding=0.5cm]{layaureo}
\usepackage{setspace}
\usepackage{siunitx}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{breqn}
\usepackage{subcaption}
\usepackage{url}
\usepackage{pgfplots}
\pgfplotsset{
    grid=both,
    major grid style={dashed, draw=gray!40},
    minor grid style={dashed, draw=gray!15},
    every axis/.append style={
        label style={font=\small},
        tick label style={font=\tiny}},
    compat=newest}
\usepgfplotslibrary{units}


\begin{document}

    \chapter{Test}

    \begin{figure*}[t]
        \centering
        \begin{subfigure}{0.48\linewidth}
            \centering
            \begin{tikzpicture}
            \begin{axis}[
            xmode=log,
            ymode=normal,
            xlabel=$frequency$,
            x unit=\si{\hertz},
            ylabel=$attenuation$,
            y unit=\si{\decibel},
            width=\linewidth,
            no marks
            ]
            \addplot [thick,black]
            table[x=freq,y=mod1,col sep=space] {file.csv};
            \end{axis}
            \end{tikzpicture}
            \caption{}
            \label{fig:test1}
        \end{subfigure}
        \hspace{5pt}
        \begin{subfigure}{0.48\linewidth}
            \centering
            \begin{tikzpicture}
            \begin{axis}[
            xmode=log,
            ymode=normal,
            xlabel=$frequency$,
            x unit=\si{\hertz},
            ylabel=$attenuation$,
            y unit=\si{\decibel},
            width=\linewidth,
            no marks
            ]
            \addplot [thick,black]
            table[x=freq,y=mod2,col sep=space] {file.csv};
            \coordinate (A) at (axis cs:0,-74.927351816709300);
            \coordinate (B) at (axis cs:0,-87.967485127488640);
            \coordinate (O1) at (rel axis cs:0,0);
            \coordinate (O2) at (rel axis cs:1,0);              
            \draw [red,sharp plot,dashed] (A -| O1) -- (A -| O2);
            \draw [blue,sharp plot,dashed] (B -| O1) -- (B -| O2);
            \end{axis}
            \end{tikzpicture}
            \caption{}
            \label{fig:test2}
        \end{subfigure}%
        \caption{This is a test.}
        \label{fig:vcm2diff_ele}
    \end{figure*}

\end{document}

and a part of my csv file (the original has more than 100k rows)

freq mod1 pole1_1 pole1_2 zero1_1 zero1_2 mod2 pole2_1 pole2_2 zero2_1 zero2_2
0.01 -57.0934586472708 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273518167093 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0102329299228075 -57.0934594712561 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273518315012 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.010471285480509 -57.0934603340746 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273518469901 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0107151930523761 -57.0934612375562 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273518632091 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0109647819614319 -57.0934621836174 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273518801924 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0112201845430196 -57.093463174265 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273518979761 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0114815362149688 -57.0934642116001 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.927351916598 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0117489755493953 -57.0934652978231 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273519360974 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0120226443461741 -57.0934664352379 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273519565159 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0123026877081238 -57.0934676262571 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273519778966 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0125892541179417 -57.093468873407 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.927352000285 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0128824955169313 -57.093470179333 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273520237285 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0131825673855641 -57.0934715468049 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273520482769 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0134896288259165 -57.0934729787235 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273520739822 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0138038426460289 -57.0934744781258 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273521008989 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0141253754462275 -57.0934760481922 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273521290842 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0144543977074593 -57.0934776922531 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273521585979 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0147910838816821 -57.0934794137956 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273521895024 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0151356124843621 -57.0934812164712 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273522218635 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0154881661891248 -57.0934831041036 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273522557497 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0158489319246111 -57.0934850806965 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273522912329 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0162181009735893 -57.0934871504426 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273523283883 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0165958690743756 -57.0934893177318 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273523672949 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0169824365246174 -57.0934915871612 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.927352408035 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0173780082874938 -57.0934939635443 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273524506952 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0177827941003892 -57.0934964519217 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273524953659 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0181970085860998 -57.0934990575713 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273525421418 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0186208713666287 -57.0935017860199 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273525911223 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0190546071796325 -57.0935046430547 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273526424111 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0194984459975805 -57.0935076347355 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273526961171 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0199526231496888 -57.093510767408 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273527523541 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0204173794466953 -57.0935140477166 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273528112416 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0208929613085404 -57.093517482619 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273528729043 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0213796208950223 -57.0935210794007 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273529374731 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0218776162394955 -57.0935248456906 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273530050849 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0223872113856834 -57.0935287894772 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273530758832 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0229086765276777 -57.0935329191253 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273531500181 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0234422881531992 -57.0935372433939 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273532276468 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0239883291901949 -57.0935417714549 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273533089341 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0245470891568503 -57.0935465129123 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273533940523 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0251188643150958 -57.0935514778226 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273534831821 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0257039578276886 -57.0935566767166 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273535765123 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0263026799189538 -57.0935621206208 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273536742412 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0269153480392692 -57.0935678210819 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273537765758 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0275422870333817 -57.0935737901901 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273538837333 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0281838293126445 -57.0935800406059 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.927353995941 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0288403150312661 -57.093586585586 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273541134368 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0295120922666639 -57.093593439012 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273542364701 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0301995172040202 -57.0936006154197 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273543653018 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0309029543251359 -57.0936081300296 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273545002051 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0316227766016838 -57.0936159987796 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273546414662 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0323593656929628 -57.0936242383587 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273547893847 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0331131121482591 -57.0936328662421 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273549442744 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0338844156139203 -57.0936419007287 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273551064639 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0346736850452532 -57.0936513609794 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.927355276297 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0354813389233576 -57.0936612670581 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273554541342 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
0.0363078054770101 -57.0936716399742 6.40405640412163 5.34407576904492 131.699566676134 26.458678866504 -74.9273556403526 63.24510750837 52.7116183559185 117.420699760983 117.420699760983
  • Welcome! Hard to say without seeing file.csv and, preferably, compilable code. – cfr Jul 18 '18 at 0:37
  • At this time I can't add the file, but it has floating values disposed on some columns separated by space. Every column has a header as first row. That's all. As soon as possible I'll post a compilable code. – thoraz Jul 18 '18 at 11:13
  • How do you get those values from that file? – cfr Jul 19 '18 at 0:43
  • I'm using the pgfplots package to graph plots. The command I use is table[x=freq,y=mod2,col sep=space] {file.csv}; – thoraz Jul 20 '18 at 10:03
  • Please make your code into a compilable example. But I meant: how do you get -74.927351816709300 and -87.967485127488640 from the values shown in the .csv you've posted? – cfr Jul 20 '18 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.