1

I'm using this code

\begin{document}
\def\xmin{5}
\def\xmax{6}
\def\domfactor{4}
\def\xmindom{\xmin/\domfactor}
\def\xmaxdom{\xmin*\domfactor}
{\color{fg}
\begin{tikzpicture}
\begin{axis}[
  title={20dB Coupler (5-6$\,\si{GHz}$)},
  xlabel={$f$ (GHz)},
  ylabel={$S$ ($\si{dB}$)},
  axis y line*=left,
  xmin=\xmin, xmax=\xmax,
  grid=major,
]
  \addplot [
    red,
  ] table[x=freq, y=s31] {data/openems_coupler.dat};
\end{axis}
\begin{axis}[
  ylabel={Directivity ($\si{dB}$)},
  axis y line*=right,
  axis x line=none,
  xmin=\xmin, xmax=\xmax,
]
  \addplot [
    orange,
  ] table[x=freq, y expr={\thisrow{s31}-\thisrow{s41}}] {data/openems_coupler.dat};
\end{axis}
\end{tikzpicture}
}
\end{document}

to create the following plot:

enter image description here

Something bugs me slightly about this, however. I'd like to have the right axis set so that the tick marks appear at the same vertical positions as the left tick marks, which would cause the grid to apply to both sides of the plot. I could, of course, omit the grid, but I like having it there.

Does pgfplots provide a way to do this, or would I have to attempt it manually (by setting ymin and max and tick set)?

3
  • 2
    I don't think pgfplots has a way of doing this, so you probably have to calculate/figure out the tick positions manually. Commented Aug 21, 2020 at 6:02
  • 1
    Note that you have 4 ticks on the left and 5 on the right. You can specify the ticks so that there are the same number and the same offset relative to their respective ymin and ymax. OTOH, the numbers will not be pretty. See also tex.stackexchange.com/questions/153792/… Commented Aug 21, 2020 at 14:19
  • Torbjørn T. is right. There is no automatic way of doing this. But specifying ymins, ymaxs and ytick distance(s) by hand should do the trick. Commented Aug 25, 2020 at 16:30

0

You must log in to answer this question.

Browse other questions tagged .