TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For pgfplots, in all the 2D examples I've seen, and in the manual, the location of axes seems to be specified in terms of location within the plot box, i.e.,relative to top, bottom. How does one specify that x- and y-axes intersect at the origin? And how does that they go through some other user-specified coordinate pair?

share|improve this question
up vote 12 down vote accepted

As Joseph said, to get the axis lines to pass through the origin, you can use the axis lines=middle option:

    axis lines=middle
\addplot {x^2+rand};

To choose an arbitrary point for the axis lines to pass through, a pragmatic approach might be to transform the data points and the labels using the x filter/.code and xticklabel keys, which can be wrapped in a custom style like axis lines origin={<x>,<y>}. The problem with this approach is that the tick labels can end up quite weird depending on the origin you choose.

    axis line origin/.style args={#1,#2}{
        x filter/.append code={ % Check for empty or filtered out numbers
        y filter/.append code={

    axis lines=middle,
    axis line origin={1,2}
\addplot +[domain=-2:2] {x^2+rand};

share|improve this answer

To plot an axis through the origin, you want the slightly misleading middle position:

\begin{axis}[axis lines = middle]


\begin{axis}[axis x line = middle]

and so on.

share|improve this answer
I'm working on the second part :-) – Joseph Wright Jul 6 '12 at 17:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.