I would like to draw a alpha- and beta-error diagram like

enter image description here

However, I do not get the areas near the cut-off coloured...

What I have done yet:

% Achsen zeichnen
\draw[->,thick] (0,0) -- (10,0) node[below] {$x$};
\draw[->,thick] (0,0) -- (0,3.5) node[left] {$y$};
% Achsen beschriften
\draw (1,-.2) -- (1,0) node[below=4pt] {$\scriptstyle1$};
\draw (3.141,-.2) -- (3.141,0) node[below=4pt] {$\scriptstyle \pi$};
\draw (6.283,-.2) -- (6.283,0) node[below=4pt] {$\scriptstyle 2\pi$};   
\foreach \y in {0,1,2}
\draw (-.1,\y) -- (.1,\y) node[left=4pt] {$\scriptstyle\y$};

% Cut-off
\draw[-,thick] (5,0) -- (5,2.5) node[above] {cut off};

% solvent
\draw plot[domain=-.5*pi:1.5*pi] (\x+0.5*pi,{sin(\x r)+1});

% insolvent
\draw plot[domain=-.5*pi:1.5*pi] (\x+1.7*pi,{sin(\x r)+1});

\draw[gray,->] (0,0) -- (pi,0);

2 Answers 2


Here is a solution. It uses the intersections library, Because of this I drew the sine curves with the builtin sin and cos paths; the intersections library does not work well with function plots.

The intersections library computes the intersection point of the two curves; you don't have to fiddle around trying to figure it out yourself.

The code is not elegant, the paths are repeated quite often, but it gets the job done.




% Achsen zeichnen
\draw[->,thick] (0,0) -- (10,0) node[below] {$x$};
\draw[->,thick] (0,0) -- (0,3.5) node[left] {$y$};
% Achsen beschriften
\foreach \x/\xlabel in {1/1,3.141/\pi,6.283/{2\pi}}
\draw (\x,-.2) -- ++(0,0.2) node[below=4pt] {$\scriptstyle\xlabel$};   
\foreach \y in {0,1,2}
\draw (-.1,\y) -- ++(0.1,0) node[left=4pt] {$\scriptstyle\y$};

% solvent
\path[name path = solvent] (0,0) cos (0.5*pi,1) sin (pi,2) cos (1.5*pi,1) sin (2*pi,0);

\path[shift={(1.2*pi,0)},name path= unsolvent] (0,0) cos (0.5*pi,1) sin (pi,2) cos (1.5*pi,1) sin (2*pi,0);

\clip[name intersections={of=solvent and unsolvent}] (intersection-1 |- {(0,0)}) rectangle (2*pi,2);
\fill[blue] (0,0) cos (0.5*pi,1) sin (pi,2) cos (1.5*pi,1) sin (2*pi,0);

\clip[name intersections={of=solvent and unsolvent}] (0,0) rectangle (intersection-1 |- {(0,2)});
\fill[shift={(1.2*pi,0)},red] (0,0) cos (0.5*pi,1) sin (pi,2) cos (1.5*pi,1) sin (2*pi,0);

% solvent
\draw[blue] (0,0) cos (0.5*pi,1) sin (pi,2) cos (1.5*pi,1) sin (2*pi,0);

\draw[shift={(1.2*pi,0)},red] (0,0) cos (0.5*pi,1) sin (pi,2) cos (1.5*pi,1) sin (2*pi,0);

\draw [thick,green, name intersections={of=solvent and unsolvent}]
    (intersection-1 |- {(0,0)}) -- ++(0,2) node[above] {cut off};



The result is:

enter image description here


A MetaPost version, included in a LuaLaTeX program. I've used MetaPost's built-in facilities for finding paths intersections and the areas between them, most notably the buildcycle macro which determines the cyclic path around this area. See the MetaPost manual, p. 30.

\documentclass[12pt, border = 1bp]{standalone}

input mpcolornames;

% Drawing a function curve
vardef function(expr xmin, xmax, xstep)(text f_x) =
    save x; x := xmin;
    (x, f_x)
        hide(x := x + xstep)
        exitunless x <= xmax;
        .. (x, f_x)
    if x - xstep < xmax: hide(x := xmax) .. (x, f_x) fi


    % Scale and axes: definitions
    numeric u, v, xmin, xmax, ymin, ymax;
    u = cm; v = 2.5cm; xmin = 0; xmax = 3pi+1; ymin = 0; ymax = 2.25;
    path xaxis, yaxis;
    xaxis = origin -- (xmax*u, 0);
    yaxis = origin -- (0, ymax*v);

    % Axes, sin waves, areas: definitions
    numeric t[], xintersect; pair intersect;
    path wave[], midstraight;
    wave1 = (function(-.5pi, 1.5pi, .05)(1 + sin x)) xyscaled (u, v) xshifted .5pi*u;
    wave2 = wave1 xshifted pi*u;
    intersect = wave1 intersectionpoint wave2;
    xintersect = xpart intersect;
    midstraight = (xintersect, -.5v) -- intersect;

    % Drawing sin waves, areas below and relevant labels
    fill buildcycle(xaxis, midstraight, wave1) withcolor .8white;
    fill buildcycle(midstraight, reverse wave2, xaxis) withcolor LightSteelBlue;
    draw wave1; draw wave2; draw midstraight;
    dotlabel.top("$\mu_0$", point 0.5 along wave1);
    label.rt("$\alpha$", point .3 along (wave1 cutbefore wave2));
    dotlabel.top("$\mu_1$", point 0.5 along wave2);
    label.lft("$\beta$", point 0.7 along (wave2 cutafter wave1));

    % Axes drawings and relevant labels
    drawarrow xaxis; drawarrow yaxis;
    label.bot("$x$", (xmax*u, 0));
    label.lft("$p(x)$", (0, ymax*v));
    label.bot("Annahme", point 0 of wave2);
    label.bot("Ablehnung", point infinity of wave1);
    label.bot("$+k_\alpha$", point 0 of midstraight);

    % Comments
    path comment_line;
    comment_line = ((xintersect - 1.25pi*u, 0)-- (xintersect + 1.25pi*u, 0)) 
        yshifted -.3v;
    drawdblarrow comment_line;
    labeloffset := .5v;
            $\beta$-Fehler kleiner,\\ $\alpha$-Fehler gr\"o\ss er
        \end{tabular} etex, point .25 of comment_line);
        \begin{tabular}{c} $\alpha$-Fehler kleiner,\\ $\beta$-Fehler gr\"o\ss er 
        \end{tabular} etex, point .75 of comment_line);



enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.