Reputation: 53
I'm trying to set up a plot with two y-axis, a Bode plot with amplitude and phase in the same diagram. I use the tikzpicture package with \begin{axis} and \addplot to overlay two graphs. Well, at least that's the idea... The issue I have is that it seems I don't have control over the graphs. I can't set fix intervals for the axis, can't control color/style of plot lines. Please point out if there's something wonky in my try to make a Bode plot. In particular, how do I set style on the lines, one dashed and one solid?
\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}
Here's some test data for the plot, if needed: https://dl.dropboxusercontent.com/u/43498716/cg_sweep.dat
Thanks!
Upvotes: 3
Views: 2074
Reputation: 17999
Is this what you are trying to achieve?
Here is a pgfplots solution.
Example for setting the intervals:
xmin=10, xmax=1000000
, ymin=10, ymax=35,
...
Example for setting the plot line color and style:
\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}
Upvotes: 2