12

I would like to know whether and how the pgfplots package can be used to produce a plot with two curves using different scales, like in the following example: enter image description here

1 Answers1

12

See section 4.8.10 – "Two Ordinates (y axis) or Multiple Axes" – in the pgfplots manual. The following is ripped from the first example (with preamble added):

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{width=7cm,compat=1.3}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    scale only axis,
    xmin=-5,xmax=5,
    axis y line*=left,% the ’*’ avoids arrow heads
    xlabel=$x$,
    ylabel=First ordinate]
  \addplot {x^2};
  \end{axis}
  \begin{axis}[
    scale only axis,
    xmin=-5,xmax=5,
    axis y line*=right,
    axis x line=none,
    ylabel=Second ordinate]
    \addplot[red] {3*x};
  \end{axis}
\end{tikzpicture}

\end{document}
N.N.
  • 36,163
  • Thanks for the answer. -- For anyone else searching for that manual section: in the current version (pgfglots 1.14) it moved to section 4.9.11. – mschuett Oct 05 '16 at 15:23