# How to generate a separate legend picture?

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 ]
color=mycolor1,
solid,forget plot
]

color=mycolor2,
solid,
forget plot
]

color=mycolor3,
solid,
forget plot
]

color=mycolor4,
solid,
forget plot
]

color=mycolor5,
solid,
forget plot
]

\end{axis}

\end{tikzpicture}%

-

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.

-