[Tex/LaTex] Background color of legend in graphics made with tikzpicture/pgfplots

colorlegendpgfplotstikz-pgf

I'm using tikzpicture and pgfplots to make graphics.

And, I'm wanting a beamer presentation with black font and white writing.

When I'm plotting the graph, the legend box is just a white box and I can't see what's written inside.

I would like to have this box "compatible with my document", I mean have a black box with text in white and white sides.

Here is my MWE :

\documentclass{beamer}

\usepackage{etex}

\usepackage[frenchb]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage{pgfplots}
\usepackage{epstopdf}
\usepackage{tikz}
\usepackage{pstricks}
\usepackage{hyperref}
\usepackage{version}
\usepackage{graphicx}


\setbeamercolor{background canvas}{bg=black}
\setbeamercolor{normal text}{fg=white}

\begin{document}
\begin{frame}

\begin{tikzpicture}

\begin{axis}[
legend entries={$test$},
xlabel={xlabel},
ylabel={ylabel},
axis on top
]
\addplot [fg, dashed, mark=*, mark size=1]
coordinates {
(0,72.01)
(5,31)
(10,56.18)
(15,51.17)
(20,47.21)
(25,30)
(30,41.09)
(40,36.51)
(50,12)
(20,29.83)
(70,27.48)
(80,25.54)
(90,24.37)
(100,22.51)
};
\end{axis}

\end{tikzpicture}


\end{frame}
\end{document}

Best Answer

Add legend style={fill=black,draw=white} to the axis options.

enter image description here

\documentclass{beamer}
\usepackage{pgfplots}
\setbeamercolor{background canvas}{bg=black}
\setbeamercolor{normal text}{fg=white}

\begin{document}
\begin{frame}

\begin{tikzpicture}

\begin{axis}[
legend entries={$test$},
legend style={fill=black,draw=white},
xlabel={xlabel},
ylabel={ylabel},
axis on top
]
\addplot [fg, dashed, mark=*, mark size=1]
coordinates {
(0,72.01)
(5,31)
(10,56.18)
(15,51.17)
(20,47.21)
(25,30)
(30,41.09)
(40,36.51)
(50,12)
(20,29.83)
(70,27.48)
(80,25.54)
(90,24.37)
(100,22.51)
};
\end{axis}

\end{tikzpicture}


\end{frame}
\end{document}