3

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}
3
  • Specify the domain: \addplot3[domain=-0.2:1,...... – user11232 Apr 7 '15 at 23:00
  • @HarishKumar That works wonders, thank you. If you like, post that as an answer too. – JohnK Apr 7 '15 at 23:04
  • John I have added an answer, and add samples too for sharp edges. – user11232 Apr 7 '15 at 23:09
1

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

1
  • Much appreciated! – JohnK Apr 7 '15 at 23:10

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.