[Tex/LaTex] How to mark a point in a pgfplot and make sure its visible (on top of the plot)

pgfplotstikz-pgf

Recently, I have TikZ'ed the following image for Wikipedia (see file)

enter image description here

I would like to mark the green dot like it was done here:

enter image description here

I've tried a couple of different things, but no matter what I did the text was always below the plot. How can I mark the green dot with its coordinates?

MWE

TeX

\documentclass[varwidth=true, border=5pt]{article}
\usepackage[active,tightpage]{preview}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning} 
\usepackage{helvet}
\usepackage[eulergreek]{sansmath}

\begin{document}
\begin{preview}
\begin{tikzpicture}
    \begin{axis}[
        width=13.4cm,
        height=10.0cm,
        % Grid
        grid = major,
        % size
        xmin= 40,     % start the diagram at this x-coordinate
        xmax= 90,   % end   the diagram at this x-coordinate
        ymin= 0,     % start the diagram at this y-coordinate
        ymax= 60, % end   the diagram at this y-coordinate
        % Legende
        legend style={
            font=\large\sansmath\sffamily,
            at={(0.5,-0.18)},
            anchor=north,
            legend cell align=left,
            legend columns=-1,
            column sep=0.5cm
        },
        % Ticks
        tick align=inside,
        every axis/.append style={font=\large\sansmath\sffamily},
        minor tick style={thick},
        scaled y ticks = false,
        % Axis
        axis line style = {very thick,shorten <=-0.5\pgflinewidth},
        axis lines = middle,
        axis line style = very thick,
        xlabel=Gesamtausgaben,
        x label style={at={(axis description cs:0.5,-0.05)},
                       anchor=north,
                       font=\boldmath\sansmath\sffamily\Large},
        ylabel=Luxusausgaben,
        y label style={at={(axis description cs:-0.05,0.5)},
                       anchor=south,
                       rotate=90,
                       font=\boldmath\sansmath\sffamily\Large}
        ]
\addplot[
scatter,
only marks,
point meta=explicit symbolic,
scatter/classes={
a={mark=x,red!90!black},%
b={mark=x,cyan!50!black}},
]
table[col sep=comma, meta=label] {data.csv};

\addplot[
scatter,
only marks,
point meta=explicit symbolic,
scatter/classes={
b={mark=*,mark size=4pt,red!30!white,draw=black},%
c={mark=*,mark size=4pt,cyan!30!white,draw=black},%
a={mark=*,mark size=4pt,green!70!black,draw=black,pin=135:{\color{black}$(65, 35)$},label={(65, 35)}] {}}},
]
table[meta=label] {
    x   y   label
    65  35  a
    70  40  b
    60  20  c
};
% \addlegendentry{Gruppe 1}
% \addlegendentry{Gruppe 2}
\end{axis}
\end{tikzpicture}
\end{preview}
\end{document}

Data

The data was generated by the following Python script

#!/usr/bin/env python

import matplotlib.pyplot as plt
import numpy
import csv


def main(n):
    cov = [[25, 20], [20, 25]]

    meanI = [70, 40]
    datapointsI = n

    meanII = [60, 20]
    datapointsII = n

    dataI = numpy.random.multivariate_normal(meanI, cov, datapointsI).T
    x, y = dataI
    plt.plot(x, y, 'x')

    dataII = numpy.random.multivariate_normal(meanII, cov, datapointsII).T
    x, y = dataII
    plt.plot(x, y, 'x')

    plt.axis('equal')
    plt.show()

    data = []
    xs, ys = dataI
    for x, y in zip(xs, ys):
        data.append([x, y, 'a'])
    xs, ys = dataII
    for x, y in zip(xs, ys):
        data.append([x, y, 'b'])

    # Write data to csv files
    with open("data.csv", 'wb') as csvfile:
        csvfile.write("x,y,label\n")
        spamwriter = csv.writer(csvfile, delimiter=',',
                                quotechar='"', quoting=csv.QUOTE_MINIMAL)
        for datapoint in data:
            spamwriter.writerow(datapoint)

if __name__ == "__main__":
    from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
    parser = ArgumentParser(description=__doc__,
                            formatter_class=ArgumentDefaultsHelpFormatter)
    parser.add_argument("-n",
                        dest="n", default=2000, type=int,
                        help="how many points should get generated")
    args = parser.parse_args()
    main(args.n)

If you don't want to execute that script, you can also download the data from the repository: https://github.com/MartinThoma/LaTeX-examples/tree/master/tikz/csv-2d-gaussian-multivarate-distributions

Best Answer

label and pin are node options, but the plot markers are not nodes, that's why those options don't produce any output.

In this case, I wouldn't recommend using an \addplot command, since each of the points requires quite different styling. I'd simply use normal TikZ commands:

\documentclass[varwidth=true, border=5pt]{article}
\usepackage[active,tightpage]{preview}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning} 
\usepackage{helvet}
\usepackage[eulergreek]{sansmath}

\begin{document}
\begin{preview}
\begin{tikzpicture}
    \begin{axis}[
            clip mode=individual,
        width=13.4cm,
        height=10.0cm,
        % Grid
        grid = major,
        % size
        xmin= 40,     % start the diagram at this x-coordinate
        xmax= 90,   % end   the diagram at this x-coordinate
        ymin= 0,     % start the diagram at this y-coordinate
        ymax= 60, % end   the diagram at this y-coordinate
        % Legende
        legend style={
            font=\large\sansmath\sffamily,
            at={(0.5,-0.18)},
            anchor=north,
            legend cell align=left,
            legend columns=-1,
            column sep=0.5cm
        },
        % Ticks
        tick align=inside,
        every axis/.append style={font=\large\sansmath\sffamily},
        minor tick style={thick},
        scaled y ticks = false,
        % Axis
        axis line style = {very thick,shorten <=-0.5\pgflinewidth},
        axis lines = middle,
        axis line style = very thick,
        xlabel=Gesamtausgaben,
        x label style={at={(axis description cs:0.5,-0.05)},
                       anchor=north,
                       font=\boldmath\sansmath\sffamily\Large},
        ylabel=Luxusausgaben,
        y label style={at={(axis description cs:-0.05,0.5)},
                       anchor=south,
                       rotate=90,
                       font=\boldmath\sansmath\sffamily\Large}
        ]
\addplot[
scatter,
only marks,
point meta=explicit symbolic,
scatter/classes={
a={mark=*,red!90!black, mark size=1, opacity=0.3, on layer=axis background},%
b={mark=*,cyan!50!black, mark size=1, opacity=0.3}},
]
table[col sep=comma, meta=label] {data.csv};

\filldraw [fill=red!50, draw=white, thick] (axis cs:70,40) circle [radius=4pt];
\filldraw [fill=cyan!50, draw=white, thick] (axis cs:60,20) circle [radius=4pt];
\filldraw [fill=yellow, draw=black, thick] (axis cs:65,35) circle [radius=4pt] node [label={[inner sep=1pt, fill=white,text=black, fill opacity=0.75, text opacity=1]above left:$(65, 35)$}] {};

% \addlegendentry{Gruppe 1}
% \addlegendentry{Gruppe 2}
\end{axis}
\end{tikzpicture}
\end{preview}
\end{document}
Related Question