乳胶 - 尝试集合博德情节

时间:2015-11-04 13:17:24

标签: plot latex tikz

我试图在同一个图中设置一个带有两个y轴的图,一个波幅和相位的波德图。我使用带有\ begin {axis}的tikzpicture包和\ addplot覆盖两个图。好吧,至少那个想法......我的问题是我似乎无法控制图表。我无法为轴设置固定间隔,无法控制绘图线的颜色/样式。请指出在我试图制作Bode情节时是否有些不可思议的事情。特别是,如何在线条上设置样式,一个是虚线还是一个实体?

    \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 个答案:

答案 0 :(得分: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}