不同轴环境的路径之间的交点

不同轴环境的路径之间的交点

我想绘制一个 Bode 图并使用 tikz 交点显示相位裕度。
以下是我所做的:

 \documentclass{article}
 \usepackage[utf8]{inputenc}
 \usepackage[european]{circuitikz}
 \usepackage{tikz}
    \usetikzlibrary{shapes, calc, intersections}
 \usepackage{pgfplots}
 \pgfplotsset{compat=1.14}
    \usetikzlibrary{pgfplots.groupplots}
 \usepackage{siunitx}
 \usepackage{amsmath}
 \usepackage{amssymb}
 \usepackage{amsfonts}
 \usepackage{subcaption}
 \renewcommand*{\j}{\mathrm{j}}
 \begin{document}
 \begin{figure}[h]
        \begin{tikzpicture}[trim axis right, remember picture]
            \begin{semilogxaxis}[
                name=mag,
                width=\linewidth,
                height=0.5\linewidth,
                ylabel=$20\log_{10}\left(|H\!(\j2\pi f)\right|)$,
                %xlabel=$f\,/\,\si{\Hz}$,
                xmin=1000, xmax=1e10,
                grid=both, minor grid style=dotted, minor y tick num = 4,
                xticklabels={}]

            \addplot [thick, name path=mag] table[x=Magnitude X, y=Magnitude Y, col sep=comma] {bode.csv};
            \draw[red, thick, name path=0dB] (axis cs:1e3,0) -- (axis cs:1e10,0);
            \end{semilogxaxis}

            \begin{semilogxaxis}[
                name=phase,
                at={($(mag.south) - (0,0.05\linewidth)$)},
                anchor=north,
                width=\linewidth,
                height=0.5\linewidth,
                xmin=1000, xmax=1e10,
                xlabel=$f\,/\,\si{\Hz}$,
                ylabel=$\arg\{H(\j2\pi\omega)\}$,
                grid=both, minor grid style=dotted, minor y tick num = 4]

                \addplot [thick, name path= phase] table[x=Phase X, y=Phase Y, col sep=comma] {bode.csv};
                \draw[red, thick, name path= PM] (axis cs:1e3,0) -- (axis cs: 1e10,0) coordinate (pmend);
            \end{semilogxaxis}
            \path [draw, name intersections={of=mag and 0dB,by={intmag}}, name path=vertical] (intmag) coordinate (IM) -- (IM|-phase.south);
            \draw [latex-latex, name intersections={of=vertical and PM, by={intpm}}] (intpm) -- (intpm|-pmend) node[midway, left] {$PM$};
        \end{tikzpicture}
        \caption{Closed-loop Bode plot without Miller compensation}
    \end{figure}
    \end{document}

这是我的结果。 enter image description here 这是错误的。它应该看起来与这张图片中的粉红色线条相似。 enter image description here 我认为我的代码的问题与在轴环境内外使用的坐标系有关,这导致结果错误。
我该如何修复它?
谢谢

PD:csv 文件这里

答案1

感谢您的更新。也许最简单的方法是提取上图交点的 x 值,并在下图中使用它来获取第二个交点。另请参阅这个答案为什么你的交叉路口被移动了。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepgfplotslibrary{groupplots,fillbetween}
\usepackage{siunitx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{subcaption}
\renewcommand*{\j}{\mathrm{j}}
\begin{document}
\begin{figure}[h]
\begin{tikzpicture}[trim axis right, remember picture]
 \begin{groupplot}[group style={group size=1 by 2,
  horizontal sep=0pt,vertical sep=12pt},%disabledatascaling,
  height=0.5\linewidth,width=\linewidth,xmode=log, ymode=normal]
    \nextgroupplot[
%        name=mag,
        ylabel=$20\log_{10}\left(|H\!(\j2\pi f)\right|)$,
        %xlabel=$f\,/\,\si{\Hz}$,
        xmin=1000, xmax=1e10,
        grid=both, minor grid style=dotted, minor y tick num = 4,
        xticklabels={}]

    \addplot [thick, name path=mag] table[x=Magnitude X, y=Magnitude Y, col sep=comma] {bode.csv};
    \draw[red, thick, name path=0dB] (axis cs:1e3,0) -- (axis cs:1e10,0);
    \path [name intersections={of=mag and 0dB,by={intmag}}]
    (intmag) \pgfextra{\pgfplotspointgetcoordinates{\pgfpointanchor{intmag}{center}}
    \xdef\myx{\pgfkeysvalueof{/data point/x}}\typeout{\myx}};
    \nextgroupplot[
        name=phase,
        xmin=1000, xmax=1e10,
        xlabel=$f\,/\,\si{\Hz}$,
        ylabel=$\arg\{H(\j2\pi\omega)\}$,
        grid=both, minor grid style=dotted, minor y tick num = 4]

   \addplot [thick, name path global=phase] table[x=Phase X, y=Phase Y, col sep=comma] {bode.csv};
   \draw[red, thick, name path global=PM] (axis cs:1e3,0) -- (axis cs: 1e10,0) coordinate (pmend);
   \path[name path=vert] (\myx,0) coordinate(low) -- (\myx,200);
   \path [name intersections={of=vert and phase,by={vertPM}}];
 \end{groupplot}
 %\path [draw,name path=vertical] (intmag) coordinate (IM) -- (IM|-phase.south);
 \draw (intmag) -- (low);
 \draw [latex-latex] (low) -- (vertPM) node[midway, left] {$PM$};
\end{tikzpicture}
\caption{Closed--loop Bode plot without Miller compensation.}
\end{figure}
\end{document}

enter image description here

相关内容