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 Answer 1

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}
1
  • 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 5, 2016 at 15:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .