Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to generate a tikzpicture which only contains the legends, and not the plots themselves. I use the following code and it returns an error: ! Package pgfplots Error: Sorry, the supplied plot command is unknown or unsupp orted by pgfplots! Ignoring it..

How to correctly add a legend to an empty axis?

% defining custom colors
\definecolor{mycolor1}{rgb}{0.02,0.06,0.18}
\definecolor{mycolor2}{rgb}{0.048,0.144,0.432}
\definecolor{mycolor3}{rgb}{0.076,0.228,0.684}
\definecolor{mycolor4}{rgb}{0.136,0.328,0.904}
\definecolor{mycolor5}{rgb}{0.388,0.524,0.932}
\begin{tikzpicture}

\begin{axis}[hide axis,legend entries={{111},{222},{333},{444},{555}},
legend columns=-1 ]
\addplot [
color=mycolor1,
solid,forget plot
]

\addplot [
color=mycolor2,
solid,
forget plot
]

\addplot [
color=mycolor3,
solid,
forget plot
]

\addplot [
color=mycolor4,
solid,
forget plot
]

\addplot [
color=mycolor5,
solid,
forget plot
]

\end{axis}

\end{tikzpicture}%
share|improve this question

1 Answer 1

up vote 2 down vote accepted

Your \addplot command is illegal: it has not data. That explains the error message.

There are a couple of "builtin" ways to create a separate legend: the first is to separate a legend from an existing axis in your document. This can be done by means of either legend to name (compare the manual) or \label/\ref (also described in the manual).

The alternative is to create a TikZ matrix with suitable styles.

A streamlined variant has been proposed in

Using a pgfplots-style legend in a plain-old tikzpicture

Perhaps that should become part of pgfplots.

share|improve this answer

Your Answer

 
discard

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.