# Monte Carlo Method Drawing

I would like to produce a Monte-Carlo-Plot with tikz and pgfplots, similar to this: Filling specified area by random dots in TikZ

I've tried defining the quarter-circle as a function (y=sqrt(1-x^2). Looks kind of ugly.

So I've tried the method submitted by Claudio Fiandrino.

\begin{tikzpicture}

\draw [-latex, thick] (0, 0) -- (0, 6) node  [above] {\Large{$y$}};
\draw [-latex, thick] (0, 0) -- (6, 0) node  [right] {\Large{$x$}};
\draw [thick] (0, 5) -- (5, 5);
\draw [thick] (5, 0) -- (5, 5);

\draw [thick] (5,0 ) arc (0:90:5);

\clip (5, 0) arc (0:90:5)--++(5,0) arc(160:320:0);
\drawdiagram[
num points=600,
use points equal width,
point width=0.5pt,
point fill color=blue,
random point diagram] at (0, 0){};
\end{tikzpicture}


This is as far as I got. How do I get red dot in the other area? I just want a plain plot, no animation.

You can also generate points and evaluate them with pgfmathparse.

\documentclass{article}
\usepackage[natural, table, fixpdftex, hyperref]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,matrix,calc}

%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{2pt}%
%%%>

\def\x{0}
\def\y{0}
\def\k{0}

\begin{document}
\begin{tikzpicture}
\foreach \i in {1,2,...,1000}{%
\typeout{Point \i}%
\typeout{X \x}%
\typeout{Y \y}%
\typeout{im Kreis?: \k}%
\pgfmathparse{ifthenelse(\k==1,"red","blue")}%
\fill[\pgfmathresult] (\x,\y)circle(0.5pt);%
}
\end{tikzpicture}
\end{document} cheers!

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. May 12, 2015 at 14:09

You can use two different clipping with the help of scopes:

\begin{tikzpicture}

\draw [-latex, thick] (0, 0) -- (0, 6) node  [above] {\Large{$y$}};
\draw [-latex, thick] (0, 0) -- (6, 0) node  [right] {\Large{$x$}};
\draw [thick] (0, 5) -- (5, 5);
\draw [thick] (5, 0) -- (5, 5);

\draw [thick] (5,0 ) arc (0:90:5);

\begin{scope}
\clip (5, 0) arc (0:90:5)--++(5,0) arc(160:320:0);
\node[
num points=600,
use points equal width,
point width=0.5pt,
point fill color=blue,
random point diagram] at (0, 0){};
\end{scope}
\begin{scope}
\clip (5, 0) arc (0:90:5)  -- (0,0) -- cycle;
\node[
num points=600,
use points equal width,
point width=0.5pt,
point fill color=red,
random point diagram] at (0, 0){};
\end{scope}
\end{tikzpicture}

• Please complete the snippet to a full document example. May 12, 2015 at 14:39