[Tex/LaTex] How to plot the maximum and the minimum

gnuplotpgfplotstikz-pgf

I am interested in drawing the minimum and the maximum of two variables, i.e. min(x,y) or max(x,y). The way I was going about doing it so far was to get the contour plots using gnuplot but my attempts have not been successful.

The plots do not show well and I am not quite sure what the reason is. Here is what the code at the end of my post produces:

enter image description here

This is far from the actual functions, unfortunately. The maximum should be a square and the minimum two orthogonal lines as in the plot below.

enter image description here

Could you please help me reproduce these functions, if possible by adjusting my code?

Thank you in advance.

\documentclass[11pt,a4paper]{article}
    \usepackage{fullpage}
    \usepackage{graphicx}
    \usepackage{indentfirst}
    \usepackage{pgfplots}
    \usepackage{tikz}
    \usepackage[miktex]{gnuplottex}
    \pgfplotsset{compat=1.12}
    \usepackage{amsmath}
    \usepackage{natbib}
    \usepackage{amssymb}
    \usepackage{xcolor}
    \usepackage{hyperref}
    \hypersetup{
        colorlinks,
        linkcolor={red!50!black},
        citecolor={black!50!black},
        urlcolor={blue!80!black}

    \begin{document}
    \begin{tikzpicture}[scale=0.8]
    \begin{axis}[
    axis lines=left,
    view={0}{90},
    xlabel=$P_1$,
    ylabel=$P_2$,
    xmin=0,xmax=1,
    ymin=0,ymax=1,
    ]
    \addplot3[
    contour gnuplot={levels={0.02}}
    ]
    {min(x,y)};
    \end{axis}
    \end{tikzpicture}\begin{tikzpicture}[scale=0.8]
    \begin{axis}[
    axis lines=left,
    view={0}{90},
    xlabel=$P_1$,
    ylabel=$P_2$,
    xmin=0,xmax=1,
    ymin=0,ymax=1,
    ]
    \addplot3[
    contour gnuplot={levels={0.2}}
    ]
    {max(x,y)};
    \end{axis}
    \end{tikzpicture}

    \end{document}

Best Answer

Add the domain and samples to the \addplot3 options.

\documentclass[11pt,a4paper]{article}
    \usepackage{pgfplots}
    \usepackage[miktex]{gnuplottex}
    \pgfplotsset{compat=1.12}


    \begin{document}
    \begin{tikzpicture}[scale=0.8]
    \begin{axis}[
    axis lines=left,
    view={0}{90},
    xlabel=$P_1$,
    ylabel=$P_2$,
    xmin=-0.2,xmax=1,
    ymin=-0.2,ymax=1,
    ]
    \addplot3[
    domain=-0.2:1,samples=100,contour gnuplot={levels={0.02}}
    ]
    {min(x,y)};
    \end{axis}
    \end{tikzpicture}\begin{tikzpicture}[scale=0.8]
    \begin{axis}[
    axis lines=left,
    view={0}{90},
    xlabel=$P_1$,
    ylabel=$P_2$,
    xmin=0,xmax=1,
    ymin=0,ymax=1,
    clip=false
    ]
    \addplot3[
    domain=0:1,samples=100,contour gnuplot={levels={0.9}}
    ]
    {max(x,y)};
    \end{axis}
    \end{tikzpicture}

    \end{document}

enter image description here

Related Question