I would like to draw two x axes with ticks and legends in the bottom and top axes where one axis is a linear transformation of the other for the same y range. There is a similar application described in section 4.8.10 of the pgfplots manual for two y axes. Are two x axes possible using the axis environment?

  • Have you tried adopting the example to use two x-axes? If so, what didn‘t work?
    – Psirus
    Jan 13, 2012 at 16:39
  • Using the same example substituting x by y, two axes appear in the upper one.
    – gypaetus
    Jan 13, 2012 at 17:57
  • Some good examples that you might find interesting are shown in this post: tex.stackexchange.com/questions/27451/…
    – agodemar
    Jan 14, 2012 at 14:34
  • What is the matter with the given answer?
    – Psirus
    Jan 16, 2012 at 21:34

1 Answer 1


As a default, both axes are plotted left/right & top/bottom. That’s why you get both ticks on the upper axis (I assume that is what you meant). You need to explicitly tell pgfplots you don’t want the upper part of the x-axis in the first {axis} by supplying axis x line*=bottom. Anyway, I find this really irritating to look at. Unless you supply additional information to the plot, there is no way of distinguishing which curve belongs to which axis, making the plot useless. Maybe in your application there is less chance of confusion, but still, beware.



      scale only axis,
      axis y line*=left,
      axis x line*=bottom]
      \addplot {x^2};
      scale only axis,
      axis y line*=right,
      axis x line*=top]
      \addplot[red] {x};

enter image description here

  • This is what I need, thanks. I have used the code without scale only axis.
    – gypaetus
    Jan 14, 2012 at 11:56
  • @MigueldeVal-Borro Reversed your edit. You are of course free to edit an answer, but it didn’t really add any new information. We try to keep the answers concise.
    – Psirus
    Jan 14, 2012 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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