7

I really want to reproduce the following diagram using Tikz.

enter image description here

I have tried the following, but I can't seem to do the curves using smooth lines.

\begin{document} \begin{center}
    \begin{tikzpicture}[scale=0.45]
        %Drawing the lines

        %Drawing the border
        \draw (0,-5) -- (0,10) -- (18,10) -- (18,-5) -- (0,-5);
        \draw (0,10);

        % curves
        \draw [red, thick] plot [smooth, tension=0.15] coordinates {(0,-5) (3.5,-1) (4.5,0) (5, 2.5)};

\end{tikzpicture}
\end{document}

The function should be the following:

enter image description here

  • 1
    Please do not just post a screenshot of the function and also explain how this function is related to the plot. How are b_1 and b_2 related to b, and why is the vertical axis labeled x_1? – marmot Mar 27 '18 at 17:12
  • @marmot Sorry. x is b_1 and b is b_2. Also, please ignore the y-axis. – pafnuti Mar 27 '18 at 17:14
9

You want TikZ, right? (I mean no pgfplots.) So here we go.

\documentclass[tikz,border=5pt]{standalone}
\begin{document}
\begin{tikzpicture}[scale=2]
\foreach \a/\Col in {0.25/blue,0.5/red,1/orange,2/purple,4/black}
{
\draw[\Col] plot[domain=0:4,variable=\x,samples=90] ({\x},{4*(\a*\x^\a)/(\a + \a*\x^\a)});
}
\draw (0,0) rectangle (4,4);
\draw [dotted] (1,0) node[below]{$1$} -- (1,4);
\draw [dotted] (0,2) node[left](p5){$0.5$} -- (4,2);
\node [left of=p5,rotate=90]{$x_1(b_1/b_2)$};
\end{tikzpicture}
\end{document}

enter image description here

Just for fun: pgfplots. Phelype was faster with that.

\documentclass[tikz,border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\tikzset{declare function={f(\x,\y)=(\y*\x^\y)/(\y + \y*\x^\y);}}
\begin{tikzpicture}

\begin{axis}[domain=0:4,ytick={0,0.5,1},xtick={0,1,2,3,4},
xmin=0,ymin=0,xmax=4,ymax=1,mark=none,samples=100] 
\foreach \a in {0.25,0.5,1,2,4}
{ 
  \addplot[very thick] {f(x,\a)};
}  
\draw[dotted] (1,0) -- (1,1);
\draw[dotted] (0,0.5) -- (4,0.5);
\end{axis}  
\end{tikzpicture}

\end{document}

enter image description here

  • If I wanted to give each curve a different colour, how would I do this? – pafnuti Mar 27 '18 at 23:23
  • @pafnuti Done. (Of course I have no idea which colors you want, but it is obvious what you have to do to adjust them.) – marmot Mar 27 '18 at 23:30
10

Using pgfplots:

enter image description here

\documentclass{article}

\usepackage[svgnames]{xcolor}
\usepackage{pgfplots}

\begin{document}

\def\b{1}

\begin{tikzpicture}
  \begin{axis}[%
    domain=0:4,
    samples=200,
    xmin=0,
    xmax=4,
    extra x ticks={1},
    extra x tick labels={},
    extra tick style={grid=major},
    xlabel={$b_1/b_2$},
    ymin=0,
    ymax=1,
    ytick={0,0.5,1},
    extra y ticks={0.5},
    extra y tick labels={},
    extra tick style={grid=major},
    ylabel={$x_1(b_1/b_2)$},
    ]
    \foreach \a/\clr in {0.25/DarkOliveGreen,
                          0.5/NavyBlue,
                            1/FireBrick,
                            2/DarkGoldenrod,
                            4/MediumSeaGreen}{%
      \expandafter\addplot\expandafter[\clr,
        line width=1pt,
        mark=none,
      ] {\a*((x/\b)^\a)/(\a*((x/\b)^\a) + \a*\b^\a)};
    }
  \end{axis}
\end{tikzpicture}

\end{document}

Ooh, too late :P

  • If I wanted to give each curve a different colour, how would I do this? – pafnuti Mar 27 '18 at 23:23
  • 1
    @pafnuti The syntax of \foreach allows you to give a list of dummy variables (here, \a/\clr), that you match in the list that the command will iterate through. So, for example, in the first iteration \a will be 0.25 and \clr, DarkOliveGreen. The TikZ solution by Mr. marmot is a little easier, the one with pgfplots requires (as far as I know) a little expansion trickery. But the colors I used are prettier than his :) – Phelype Oleinik Mar 27 '18 at 23:51

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.