[Pgfplots-features] Two Ordinates: higher level commands and legends
Brought to you by:
cfeuersaenger,
ludewich
|
From: Denis B. <dbi...@wa...> - 2012-11-14 08:31:52
|
Hello,
the "Two Ordinates (y axis) or Multiple Axes" is very useful in
technological area but, for instance for my students who follows my
LaTeX and pgfplot course (who aren't fond of computer science), the
current way to achieve the result, for instance:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tikzpicture}
% let both axes use the same layers
\pgfplotsset{set layers}
\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}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
is a bit tricky. Moreover, create a unique legend in this kind of plot
is not that easy, see for instance:
http://tex.stackexchange.com/questions/42697/pgfplots-legends-in-multiple-y-axis-plot-overlapping
So it could be nice for pgfplots to provide higher level commands, for
instance something like:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tikzpicture}
\begin{doubleaxis}[
xlabel=$x$,
yleftlabel=First ordinate,
yrightlabel=Second ordinate
]
\addplot {x^2};
\addplot {3*x};
\legend{$y=x^2$,$y=3x$}
\end{doubleaxis}
\end{tikzpicture}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
where:
1. the:
* \pgfplotsset{set layers}
* scale only axis
* xmin=..., xmax=...,
* axis y line*=left
* axis y line*=right
* axis x line=none
would be hidden in the doubleaxis definition,
2. the first addplot would be the left one and the second, the right
one,
3. the comma separated list in the \legend command's argument applies
successively to the two \addplot.
All the best.
--
Denis
|