Latex - 尝试绘制波德图

3
我正在尝试建立一个带有两个y轴的图表,即振幅和相位在同一图表上的波德图。我使用tikzpicture包中的\begin{axis}和\addplot来叠加两个图形。好吧,至少这是我的想法... 我遇到的问题是似乎我不能控制图形,无法为轴设置固定间隔,也无法控制图线的颜色/样式。请指出如果我在尝试制作波德图时有哪些奇怪的地方。特别是,如何设置线条的样式,一个虚线和一个实线?
    \begin{figure}[H]
\centering
\begin{minipage}{0.9 \textwidth}

\begin{tikzpicture}

%%% AMPLITUDE
\begin{axis}[
    width=340pt,
    height=180pt,
    xlabel=Frequency,
    xmode = log,
    ylabel=Amplitude [dB],
    axis x line=bottom,
    axis y line=left,
%   xmin=10, xmax=1000000,
%   ylabel near ticks,
    legend pos= south west,
    font=\scriptsize,
    legend style={font=\scriptsize,draw=none,fill=none}
    ]


\addplot table [color=black, mark=none,dotted,y=$amp$, x=freq, font=\scriptsize]{amp.dat};
\addlegendentry{$Amplitude$ }

\end{axis}

%%% PHASE
\begin{axis}[
    width=340pt,
    height=180pt,
%   xmin=10, xmax=1000000,
    hide x axis,
    axis y line=right,
    xmode = log,
    ylabel=Phase [deg],
%   ymin=-300, ymax=-120,   
%   ylabel near ticks,
    legend pos= north east,
    font=\scriptsize,
    legend style={font=\scriptsize,draw=none,fill=none}
    ]


\addplot table [mark=none,dashed, y=$phase$, x=freq]{phase.dat};
\addlegendentry{$Phase$ }

\end{axis}

\end{tikzpicture} 





\caption{A Bode-plot of the common source gain stage.} 
\label{fig:cg_sweep}
\end{minipage}
\end{figure}

如果需要,这里有一些用于绘图的测试数据:https://dl.dropboxusercontent.com/u/43498716/cg_sweep.dat

谢谢!

1个回答

2

您想要实现的是这样的吗?

enter image description here

这里有一个 pgfplots 的解决方案。

设置区间的示例: xmin=10, xmax=1000000ymin=10, ymax=35, ...

设置图形线条颜色和样式的示例: \addplot[red, dashed] ...

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}

\begin{document}

\begin{tikzpicture}
\pgfplotsset{set layers}
\begin{axis}[
    xmode=log,
    xmin=10, xmax=1000000,
    ymin=10, ymax=35,
    scale only axis,
    axis y line*=left,
    xlabel=Frequency,
    ylabel={Amplitude [dB]},
]
    \addplot[blue, solid] table[x=freq,y=$amp$] {cg_sweep.dat};
    \label{aplot}
\end{axis}
\begin{axis}[
    xmode=log,
    xmin=10, xmax=1000000,
    ymin=-290, ymax=-140,
    scale only axis,
    axis y line*=right,
    axis x line=none,
    ylabel={Phase [deg]},
]
    \addlegendimage{/pgfplots/refstyle=aplot}\addlegendentry{$Amplitude$}
    \addplot[red, dashed] table[x=freq,y=$phase$] {cg_sweep.dat};
    \addlegendentry{$Phase$ }
\end{axis}
\end{tikzpicture} 

\end{document}

是的,非常感谢。 (我该如何标记此问题为已解决?) - Überfuzz
1
@Überfuzz 没关系。你不需要标记问题为已解决,而是需要接受答案(就像你现在所做的那样)。请查看tour - sergej

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接