Hi John,
thank you for your interest in pgfplots!
Concerning your questions:
1. to position the legend boxes, you can use 'legend
style={at={(<x>,<y>)},anchor=<anchor name>}'.
Here, <x> and <y> are relative positions where <x>=0 means the lower x
limit and <x>=1 the upper x limit. The <anchor name> refers to a
position inside of the legend box.
Attached you find a modification to your code which places the legend
for the plots of the left axis on the left, outside of the axis, and the
legend for the plots of the right on the right (also outside of the axis).
2. The line styles are determined by the "cycle list" which is reset for
every axis. In order to get different styles for the
second axis, you can (for example), use 'cycle list shift=6'. This will
skip the first six entries.
Alternatively, you could use a different cycle list (see the manual for
details).
3. You may also want to consider ticklabel style={/pgf/number
format/1000 sep={}} to disable the 1000 separator. Furthermore, you may
be interested in 'x axis line=none' for the second axis to avoid doubled
tick labels.
I hope this answers your questions.
Best regards
Christian
PS
I CC'ed the answer to the mailing list in case there are others with
similar requests.
Am 26.09.2011 11:38, schrieb John Marius Ørke:
Hi!
Great package and extention to LaTex You have provided!
But, I have encountered a problem regarding positioning with
\addledgenentry and multiple axis.
I have created a plot with 9 lines where 6 is related to the left y
axis and the remaining 3 to the right y axis. When I compile this
figure I get the exact layout of lines as I want (except some similar
color and boxes for lines), but the boxes containing the “summary” of
the lines comes on top of each other, making it hard to figure out
which axis to compare with which lines.
What I really want is to have the legend for the 6 first lines outside
the left y axis and the legend for the last 3 lines outside the right
y axis.. Is this possible, if so how?
I have searched the web for solutions, but there seems only to be
solutions for plots only containing one set of begin-end axis..
I append the code for my graph at the end of the message.
Beforehand, Thanks for Your time!
Best regards
John Marius Ørke (Oerke/Örke)
john.o...@iot.ntnu.no <mailto:john.o...@iot.ntnu.no>
Ph.D student at the
Department of Industrial Economics and Technology Management
Norwegian University of Science and Technology
-----------------------------------------------------------------------------------------------------------------------------------------------
The code:
\begin{figure}
\centering\begin{tikzpicture}
\begin{axis}[
scale only axis,
xmin=1998, xmax=2009,
axis y line*=left,
ymin=0, ymax=1,
xlabel=Year
]
\addplot coordinates {
(1999, 0.0963)
(2000, 0.1036)
(2001, 0.0880)
(2002, 0.0799)
(2003, 0.0725)
(2004, 0.0661)
(2005, 0.0643)
(2006, 0.0582)
(2007, 0.0670)
(2008, 0.0792)
};
\addlegendentry{Left1}
\addplot coordinates {
(1999, 0.0205)
(2000, 0.0226)
(2001, 0.0182)
(2002, 0.0120)
(2003, 0.0113)
(2004, 0.0159)
(2005, 0.0160)
(2006, 0.0209)
(2007, 0.0221)
(2008, 0.0198)
};
\addlegendentry{Left2}
\addplot coordinates {
(1999, 0.2599)
(2000, 0.2512)
(2001, 0.2690)
(2002, 0.2629)
(2003, 0.2608)
(2004, 0.2408)
(2005, 0.2405)
(2006, 0.2300)
(2007, 0.2438)
(2008, 0.2464)
};
\addlegendentry{Left3}
\addplot coordinates {
(1999, 0.8364)
(2000, 0.8023)
(2001, 0.7200)
(2002, 0.6195)
(2003, 0.6275)
(2004, 0.9099)
(2005, 0.7908)
(2006, 0.7342)
(2007, 0.7077)
(2008, 0.7642)
};
\addlegendentry{Left4}
\addplot coordinates {
(1999, 0.1455)
(2000, 0.1124)
(2001, 0.2218)
(2002, 0.3392)
(2003, 0.2857)
(2004, 0.1775)
(2005, 0.1413)
(2006, 0.1494)
(2007, 0.1570)
(2008, 0.2052)
};
\addlegendentry{Left5}
\addplot coordinates {
(1999, 0.2982)
(2000, 0.3858)
(2001, 0.4507)
(2002, 0.3494)
(2003, 0.3279)
(2004, 0.4186)
(2005, 0.4769)
(2006, 0.5802)
(2007, 0.6675)
(2008, 0.6356)
};
\addlegendentry{Left6}
\end{axis}
\begin{axis}[
scale only axis,
xmin=1998, xmax=2009,
axis y line*=right,
ymax=6.5
]
\addplot coordinates {
(1999, 2.7741)
(2000, 2.7174)
(2001, 2.7094)
(2002, 2.4292)
(2003, 2.4271)
(2004, 2.5138)
(2005, 2.6314)
(2006, 2.8052)
(2007, 2.9101)
(2008, 3.2198)
};
\addlegendentry{Right1}
\addplot coordinates {
(1999, 2.1760)
(2000, 2.3869)
(2001, 1.7108)
(2002, 1.3227)
(2003, 1.7335)
(2004, 2.0454)
(2005, 2.3972)
(2006, 2.7576)
(2007, 2.6245)
(2008, 1.3329)
};
\addlegendentry{Right2}
\addplot coordinates {
(1999, 5.6390)
(2000, 5.6945)
(2001, 5.6745)
(2002, 5.2961)
(2003, 5.2264)
(2004, 5.2576)
(2005, 5.3009)
(2006, 5.3392)
(2007, 5.4563)
(2008, 6.0756)
};
\addlegendentry{Right3}
\end{axis}
\end{tikzpicture}
\caption{The caption of this figure.}
\label{fig}
\end{figure}
-------------------------------------------------------------------------------------------------------------------------
\documentclass[a4paper]{article}
\usepackage{german}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}
\begin{document}
%\tracingcommands=2\tracingmacros=2
\begin{tikzpicture}
\begin{axis}[
scale only axis,
xmin=1998, xmax=2009,
axis y line*=left,
ymin=0, ymax=1,
xlabel=Year,
legend style={at={(-0.1,1)},anchor=north east},
ticklabel style={/pgf/number format/1000 sep=},
]
\addplot coordinates {
(1999, 0.0963)
(2000, 0.1036)
(2001, 0.0880)
(2002, 0.0799)
(2003, 0.0725)
(2004, 0.0661)
(2005, 0.0643)
(2006, 0.0582)
(2007, 0.0670)
(2008, 0.0792)
};
\addlegendentry{Left1}
\addplot coordinates {
(1999, 0.0205)
(2000, 0.0226)
(2001, 0.0182)
(2002, 0.0120)
(2003, 0.0113)
(2004, 0.0159)
(2005, 0.0160)
(2006, 0.0209)
(2007, 0.0221)
(2008, 0.0198)
};
\addlegendentry{Left2}
\addplot coordinates {
(1999, 0.2599)
(2000, 0.2512)
(2001, 0.2690)
(2002, 0.2629)
(2003, 0.2608)
(2004, 0.2408)
(2005, 0.2405)
(2006, 0.2300)
(2007, 0.2438)
(2008, 0.2464)
};
\addlegendentry{Left3}
\addplot coordinates {
(1999, 0.8364)
(2000, 0.8023)
(2001, 0.7200)
(2002, 0.6195)
(2003, 0.6275)
(2004, 0.9099)
(2005, 0.7908)
(2006, 0.7342)
(2007, 0.7077)
(2008, 0.7642)
};
\addlegendentry{Left4}
\addplot coordinates {
(1999, 0.1455)
(2000, 0.1124)
(2001, 0.2218)
(2002, 0.3392)
(2003, 0.2857)
(2004, 0.1775)
(2005, 0.1413)
(2006, 0.1494)
(2007, 0.1570)
(2008, 0.2052)
};
\addlegendentry{Left5}
\addplot coordinates {
(1999, 0.2982)
(2000, 0.3858)
(2001, 0.4507)
(2002, 0.3494)
(2003, 0.3279)
(2004, 0.4186)
(2005, 0.4769)
(2006, 0.5802)
(2007, 0.6675)
(2008, 0.6356)
};
\addlegendentry{Left6}
\end{axis}
\begin{axis}[
scale only axis,
xmin=1998, xmax=2009,
axis y line*=right,
ymax=6.5,
legend style={at={(1.1,1)},anchor=north west},
axis x line=none,
cycle list shift=6,
]
\addplot coordinates {
(1999, 2.7741)
(2000, 2.7174)
(2001, 2.7094)
(2002, 2.4292)
(2003, 2.4271)
(2004, 2.5138)
(2005, 2.6314)
(2006, 2.8052)
(2007, 2.9101)
(2008, 3.2198)
};
\addlegendentry{Right1}
\addplot coordinates {
(1999, 2.1760)
(2000, 2.3869)
(2001, 1.7108)
(2002, 1.3227)
(2003, 1.7335)
(2004, 2.0454)
(2005, 2.3972)
(2006, 2.7576)
(2007, 2.6245)
(2008, 1.3329)
};
\addlegendentry{Right2}
\addplot coordinates {
(1999, 5.6390)
(2000, 5.6945)
(2001, 5.6745)
(2002, 5.2961)
(2003, 5.2264)
(2004, 5.2576)
(2005, 5.3009)
(2006, 5.3392)
(2007, 5.4563)
(2008, 6.0756)
};
\addlegendentry{Right3}
\end{axis}
\end{tikzpicture}
\end{document}
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Pgfplots-features mailing list
Pgfplots-features@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pgfplots-features