1

I need to plot the following figure in LaTeX.

enter image description here

as suggested I tried some stuff myself and so far I have reached the following:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta,automata,topaths}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
  axis lines=middle,
  axis line style={-Stealth,very thick},
  xmin=0,xmax=5.5,ymin=-5.5,ymax=6.5,
  xtick distance=1,
  xticklabels={,,},
  ytick distance=1,
  yticklabels={,,},
  xlabel=$\theta$,
  ylabel=Net Utility,
  grid=major,
  grid style={thin,densely dotted,black!20}]
\addplot [domain=0:5,samples=2] {x*2/3-0.5} node[right]{$N (Incumbent)$}; %These are not shown completely
\addplot [domain=0:5,samples=2] {x*2-4.5} node[right]{$P (new entrant)$}; %These are not shown completely
\addplot +[-Stealth,very thick,mark=none] coordinates {(5, -5.4) (5, 6.4)}; %Why is it brown colored? and how can I put the ticks in this one too?
\addplot +[mark=none] coordinates {(3, 0) (3, 4.4)};
\addplot +[mark=none] coordinates {(4.2, 0) (4.2, 4.4)}; %Why is this blue colored?
\draw (80,465)node[]{$\frac{p_{N}}{Q_{N}}$}; %What do these mean? (80,465)
\draw (240,465)node[]{$\frac{p_{P}}{Q_{P}}$};
\draw (340,465)node[]{$\frac{p_{P}-p_{N}}{Q_{P}-Q_{N}}$};
\addplot +[Stealth-Stealth,very thick,mark=none] coordinates {(3, 4.2) (4.2, 4.2)};
\draw (365,1055)node[]{$\frac{1}{p_{P}-p_{N}}$};
\addplot[red,mark=*] coordinates {(0.75,0)};
\addplot[red,mark=*] coordinates {(2.25,0)};
\addplot[red,mark=*] coordinates {(3,0)};
\addplot[red,mark=*] coordinates {(3,1.5)};
\addplot[red,mark=*] coordinates {(4.2,0)};
\end{axis}

\end{tikzpicture}


\end{document}

Which gives me this: enter image description here

But there are some problems with my attempt (I have also commented the problems I can't understand in front of the corresponding line in the above code):

  1. I cannot understand the node coordinates I have used to show the labels inside the plot (for example \draw (80,465)node[]{$\frac{p_{N}}{Q_{N}}$};) and how they turn out to put the labels. I mean it has done the thing that I wanted and it is OK. I just don't understand it. I would expect to use the coordinates (0.75,-1) (the place where $\frac{p_{N}}{Q_{N}}$ is right now) but it doesn't work and puts the label in somewhere that makes no sense
  2. (I realized this one, just add black inside the brackets and it worked)Some line segments have been colored blue or brown automatically. I like the red ones makes the plot more elegant but do not know how to change the blue and brown one back to black color.
  3. (I figured this one too. Had to change the xmax to a bigger number.) The labels in line 20 and 21 are trimmed and not shown completely.
  4. How can I also put ticks on the right hand side vertical line as same as the left vertical line?
6
  • 4
    What you try so far? With use of the library intersections this should not be big problem.
    – Zarko
    Aug 27 '20 at 9:42
  • 1
    Welcome to TeX.SX! The short answer is that, yes, this is possible but I have to warn you that questions of the form "Please draw this for me" that show no effort on the part of OP, often don't get answered. You will get more help if you post some code showing what you have tried and give a minimal working example. A quick search on TeX.SX for drawing functions (with tikz or pstricks) will give you an idea of where to start from.
    – user30471
    Aug 27 '20 at 13:17
  • 1
    Could you please reopen the question? Maybe I should change the title of the question as well
    – Mike
    Aug 28 '20 at 15:28
  • 1
    pgfplots cuts the plots to the given dimensions. You can prevent this with clip=false
    – AndréC
    Aug 29 '20 at 7:34
  • 1
    pgfplots is designed to place several function graphs on the same Cartesian (or other) coordinate system. To facilitate their visualization, it automatically colors each graph with a different color from the previous one. This is why the vertical line is blue, you have built it as the graph of a function.
    – AndréC
    Aug 29 '20 at 9:22
2

Drawing with tikz is simpler:

\documentclass[tikz, border=5mm]{standalone}
%\usepackage{pgfplots}
\usetikzlibrary{arrows.meta,
                calc,
                intersections
                }
%\pgfplotsset{compat=1.17}

\begin{document}
    \begin{tikzpicture}[y=5mm,
         > = Straight Barb,
arr/.style = {-Stealth, thick},
dot/.style = {circle, fill, minimum size=3pt,
              inner sep=0pt, outer sep=0pt},
every label/.style =  {label distance=2pt, fill=white, 
              inner sep=1pt, font=\footnotesize}
                        ]
%   axis
\draw[arr, name path=A]  
            (-0.2,0) -- (6,0) node[below  left] {$\theta$};
\draw[arr]  (0,-5.0) -- (0,6) node[below right] {Net utility};
\draw[arr]  (5,-5.0) -- (5,6);
\draw[densely dotted, gray]
            (0,-5) grid[xstep=1, ystep=0.8] (6,6);
\coordinate (O) at (0,0);
%
\draw[name path=B] 
            (0,-0.5) -- (5,2*5/3-0.5) node[right]{$N$ (Incumbent)};
\draw[name path=C]
            (0,-4.5) -- (5,2*5-4.5)   node[right]{$P$ (new entrant)};
            
% intersections
\path [name intersections={of=A and B, by=ab}]
    node[dot, label=below:$\frac{p_N\vphantom{-}}{Q_N}$] at (ab) {};
\path [name intersections={of=A and C, by=ac}]
    node[dot, label=below:$\frac{p_P\vphantom{-}}{Q_P}$] at (ac) {};
\draw [name intersections={of=B and C, by=bc}]
    (bc |- O) node[dot, label={[xshift=0.7em]below:$\frac{p_P-p_N}{Q_P - Q_N}$}] {};
%
\coordinate (d) at ($(bc) + (0,4)$);
\coordinate (e) at ($(d)  + (1.5,0)$);
\draw[densely dashed]
    (bc |- O) -- (d) 
    (e) -- (e |- O) node [dot] {};
\draw[<->]  
    ($(d) + (0,-0.5)$)  
        --  node[label={[yshift=-1ex]$\frac{1}{p_P-p_N}$}] {} 
    ($(e) + (0,-0.5)$);
             
    \end{tikzpicture}
\end{document}

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.