[Tex/LaTex] Drawing circles inside an axis environment

drawpgfplotstikz-pgf

I'm trying to draw an uppersemicontinous function, And I would like to draw a filled circle at the top line and a empty circle at the bottom line.

Here is my MWE:

\documentclass[border=0.5]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{pgfplots}[compact=1.11]
\begin{document}
\begin{tikzpicture}
\begin{axis}
        \addplot[domain=-2:2, samples = 100, color = blue!80!black] {x^2};
        \addplot[domain=2:6, samples = 100, color = blue!80!black] {-x^2+8*x-12};

        \filldraw[fill=blue!80!black,draw=blue!80!black] (2,4) circle(0.5);
        \filldraw[draw=blue!80!black,fill=white]  (2,0) circle(0.5);
\end{axis}
\filldraw[fill=blue!80!black,draw=blue!80!black] (2,4) circle(0.5);
\filldraw[draw=blue!80!black,fill=white]  (2,0) circle(0.5);
\end{tikzpicture}
\end{document} 

This returns the image:
enter image description here

With the two small circles being placed wrong and wrong in size, and the big circles being placed wrong.

Is there a way to do this?

Best Answer

I ended up defining the coordinates within the axis environment and then drawing the stuff outside.

\documentclass[border=0.5]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{pgfplots}%[compact=1.11]
\begin{document}
\begin{tikzpicture}
\begin{axis}
        \addplot[domain=-2:2, samples = 100, color = blue!80!black] {x^2};
        \addplot[domain=2:6, samples = 100, color = blue!80!black] {-x^2+8*x-12};
        \coordinate (center1) at (axis cs:2,4);
        \coordinate (center2) at (axis cs:2,0);
\end{axis}
\filldraw[fill=blue!80!black,draw=blue!80!black] (center1) circle(0.5);
\filldraw[draw=blue!80!black,fill=white]  (center2) circle(0.5);
\end{tikzpicture}
\end{document} 

enter image description here

The size has to be adjusted, but I don't know which size you were after, you only wrote 0.5.

EDIT: Here is the explanation why I decided to go this way. In more complicated scenarios, a circle may no longer be a circle if drawn in the axis environment. This happens for instance in 3D plots, consider e.g. this post: if one draws the duck there inside the axis, this will lead to something that makes one fear about the safety of the poor duck. Of course, there might be situations, in which one wants to have these deformations, or situations (like here) where it does not matter whether one draws the stuff inside or outside.