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?– PsirusJan 13, 2012 at 16:39
-
Using the same example substituting x by y, two axes appear in the upper one.– gypaetusJan 13, 2012 at 17:57
-
Some good examples that you might find interesting are shown in this post: tex.stackexchange.com/questions/27451/…– agodemarJan 14, 2012 at 14:34
-
What is the matter with the given answer?– PsirusJan 16, 2012 at 21:34
1 Answer
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.
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
scale only axis,
xmin=-5,xmax=5,
axis y line*=left,
axis x line*=bottom]
\addplot {x^2};
\end{axis}
\begin{axis}[
scale only axis,
xmin=0,xmax=15,
domain=0:15,
axis y line*=right,
axis x line*=top]
\addplot[red] {x};
\end{axis}
\end{tikzpicture}
\end{document}
-
This is what I need, thanks. I have used the code without scale only axis.– gypaetusJan 14, 2012 at 11:56
-