# How to plot a linear function with axes, arrows, and labels?

I have now spend hours by creating this figure - without luck.

I have tried different types of tikz, pstricks and multido usepackages.

The lines from a to x_2, d to x_1 and p_1 to c, should be dashed line.

If it is possible to add arrows at x,y-axis.

\documentclass[a4paper,12pt,oneside]{article}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{pgf}
\usetikzlibrary{shapes,arrows,positioning,calc}
\usepackage{tabu}
\usepackage{hyperref}
\usepackage{longtable}
\usepackage{array}
\usepackage{siunitx,multirow,tabularx,booktabs}
\usepackage{amsmath,amssymb,bm,mathtools}

\begin{document}
\begin{center}
\begin{tikzpicture}[scale=6]
\draw[->] (0,0) -- (0,1) node[left] {$P/X$};
\draw[->] (0,0) -- (1,0) node[below] {$X/t$};
\end{tikzpicture}
\end{center}

\end{document}

• Your initial efforts via \draw (x1,y1) -- (x2,y2); to start drawing some codes would be appreciated by the helpers here. – Jesse May 25 '14 at 11:49
• Hi Jesse. I tried, also with draw's but I could not type P_1, P_2, X_2, X_1 ind because I do not have any coordinates. – A. F. May 25 '14 at 11:53
• Try node[above, below, left, right](){$P_1$} which requires $math$. Further, even Minimum Non-working Example is appreciated. At least we know you have tried. – Jesse May 25 '14 at 11:55
• Many examples can be found here. For example tex.stackexchange.com/q/155181/34618 – Jesse May 25 '14 at 12:07
• People are understandably more inclined to help those who show they've tried because they know they are not just trying to get others to do all of the work for them. That is, it shows you are stuck rather than just can't be bothered. Since people help in their spare time, surely you can understand why they might feel differently about helping in the two cases? Just as importantly, even a non-working example means people don't have to start completely from scratch. So people are more motivated to help and helping is easier. Hence, you are more likely to get effective help. – cfr May 25 '14 at 12:19

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\draw [ultra thick,-latex] (0,0)--(10,0) node [right, above]{$x/t$};
\draw [ultra thick,-latex] (0,0)--(0,12) node [right]{$P/X$};
\coordinate (X2) at (4,0);
\coordinate (X1) at (6,0);
\coordinate (P1) at (0,5);
\coordinate (P2) at (0,7);
\coordinate (b)  at (4,5);
\coordinate (d)  at (6,7);
\coordinate (a)  at (4,7);
\coordinate (c)  at (6,5);
\node at (X2) [below] {$X2$};
\node at (X1) [below] {$X1$};
\node at (P2) [left] {$P2$};
\node at (P1) [left] {$P1$};
\draw [dashed] (a)node [above right] {$a$}--(X2);
\draw [dashed] (d)node [above right] {$d$}--(X1);
\draw [dashed] (P1)--(c)node [above right] {$c$};
\draw  (P2)--(d)node [above right] {$d$};
\node at (b) [above right]{$b$};
\draw (d)--++(0:2)node [right] {$MC=AC$};
\draw (c)--(a)--++(135:5.65);
\draw (c)--++(-45:2) node [below] {$D$};
\end{tikzpicture}

\end{document}


• Thank you very much, I really appreciate it. Thank you, ferahfeza! – A. F. May 25 '14 at 12:45

A PSTricks solution using the pst-plot package:

\documentclass{article}

\usepackage{pst-plot}

\begin{document}

\begin{pspicture}(-0.5,-0.45)(8.25,8) % values found manually
\psaxes[ticks = none, labels = none]{->}(0,0)(-0.2,-0.2)(7.5,7.5)[$X/t$,0][$P/X$,90]
\psyTick(0){0}
\psline(0,7)(5,2)
\uput[270](5,2){$D$}
\psline(0,5)(5,5)
\uput[0](5,5){$\mathrm{MC} = \mathrm{AC}$}
\psset{linestyle = dashed}
\psline(2,5)(2,0)
\psline(3.5,5)(3.5,0)
\psline(0,3.5)(3.5,3.5)
\uput[45](2,5){$a$}
\uput[45](2,3.5){$b$}
\uput[45](3.5,3.5){$c$}
\uput[90](3.5,5){$d$}
\uput[180](0,3.5){$P_{1}$}
\uput[180](0,5){$P_{2}$}
\uput[270](2,0){$X_{2}$}
\uput[270](3.5,0){$X_{1}$}
\end{pspicture}

\end{document}


You can automate the intersections to make the graph more fexlible lil in the following solution.

You need to load the TikZ libraries calc and intersections with

\usetikzlibrary{intersections,calc}


Inside the {tikzpicture} you then set put the coordinate system manually with

\draw [thick,->] (0,0)--(10,0) node [right, above]{$X/t$};
\draw [thick,->,name path=y axis] (0,0)--(0,12) node [right]{$P/X$};
\node at (0,0) [below left] {$0$};


Next step is to define the coordinates on the axes. Her you can use the shape coordinate to use the node names as coordinate with out thinking about finding the right anchor. And label is used to typeset the names in the picture.

\node (X2) at (4,0) [coordinate,label=below:$X_2$] {};
\node (X1) at (6,0) [coordinate,label=below:$X_1$] {};
\node (P1) at (0,5) [coordinate,label=left:$P_2$] {};
\node (P2) at (0,7) [coordinate,label=left:$P_1$] {};


Now it’s time to draw the dashed lines. her you can use the following syntax to get the perpendicular intersection of two coordinates: (A |- B) or (A -| B) where A and B must be two valid coordinates (enclosed in braces if the are like (1,2)). Again we add nodes with label as coordinates for later reference. And the line starting in P2 uses shorten > with a negative value to lengthen the line by 2cm.

\draw [dashed,shorten >=-4cm] (P2) -- (P2 -| X2)
node (a) [coordinate,label=above:$a$] {}
node [right=4cm] {$MC=AC$};
\draw [dashed] (X2) -- (a);
\draw [dashed] (P1) -- (P1 -| X1)
node (c) [coordinate,label=above right:$c$] {};
\draw [dashed] (X1) -- (P2 -| X1)
node (d) [coordinate,label=above:$d$] {};
\node at (P1 -| X2) (b) [coordinate,label=above right:$b$] {};


Last thing to do is to draw the graph; therefor you can define a helping path named graph – remember that the y axis is named too. And with the calc library you can say ($(A)!f!(B)$) where A and B again are coordinates and f is a factor lying on the line passing through A and B with the length f*((B)(A)). The line must intersect the y axis, sou can add draw,red as option to see the path.

\path [name path=graph] (c) -- ($(c)!3.1!(a)$);


And then use the intersection point to draw the graph

\draw [thick, name intersections={of=y axis and graph,by=A}] (A) -- ($(a)!2!(c)$)
node (D) [coordinate,label=below:$D$] {};


That’ll give you this result:

And now you can change P1, P2, X1 or X2 and the rest changes accordingly.

full code:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{intersections,calc}

\begin{document}
\begin{tikzpicture}
% axes
\draw [thick,->] (0,0)--(10,0) node [right, above]{$X/t$};
\draw [thick,->,name path=y axis] (0,0)--(0,12) node [right]{$P/X$};
\node at (0,0) [below left] {$0$};
% coordinates and labels
\node (X2) at (4,0) [coordinate,label=below:$X_2$] {};
\node (X1) at (6,0) [coordinate,label=below:$X_1$] {};
\node (P1) at (0,5) [coordinate,label=left:$P_2$] {};
\node (P2) at (0,7) [coordinate,label=left:$P_1$] {};
% intersections
\draw [dashed,shorten >=-4cm] (P2) -- (P2 -| X2)
node (a) [coordinate,label=above:$a$] {}
node [right=4cm] {$MC=AC$};
\draw [dashed] (X2) -- (a);
\draw [dashed] (P1) -- (P1 -| X1)
node (c) [coordinate,label=above right:$c$] {};
\draw [dashed] (X1) -- (P2 -| X1)
node (d) [coordinate,label=above:$d$] {};
\node at (P1 -| X2) (b) [coordinate,label=above right:$b$] {};
% graph
\path [name path=graph] (c) -- ($(c)!3.1!(a)$);
\draw [thick, name intersections={of=y axis and graph,by=A}] (A) -- ($(a)!2!(c)$)
node (D) [coordinate,label=below:$D$] {};
\end{tikzpicture}
\end{document}

• For further reference I recommend reading the great tutorials at the beginning of the manual of TikZ (pgfmanual.pdf)! – Tobi May 25 '14 at 13:12

A solution with pst-eucl: it depends only on four parameters — the values of the coordinates of a, b, c, d:

\documentclass[pdf, x11names]{article}%
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage{heuristica}

\begin{document}

\begin{pspicture*}(-1,-1)(8.8,8.8)
\psaxes[ticks = none, labels = none, arrows = -> ,xlabelPos = axis](0,0)(8,8)[X/t, 0][P/X, 90]
\pnode(8,0){X}\pnode(0,8){Y}
\psset{PointSymbol = none, RightAngleSize = 0}
\pstGeonode[PtNameMath = false, PosAngle = {-135,90,45,45,90}](0,0){O}(2.8,5){a}(2.8,3){b}(5,3){c}(5,5){d}
\pstProjection[CodeFig]{O}{X}{d,a}[x_1,x_2]%
\pstProjection[CodeFig]{O}{Y}{c}[p_1]
\pstProjection{O}{Y}{a}[p_2]
\psset{nodesepB = -1.5}
\pstLineAB{p_2}{d}\uput{1.7}[r](d){MC = AC}
\pstInterLL[PointName = none]{a}{c}{O}{Y}{q}
\pstLineAB[linecolor =IndianRed3,linewidth = 1.5pt]{q}{c}
\end{pspicture*}

\end{document}


• I tried your anwser, wich, btw, is very proper, but the 3 pstProjection blue dashed lines aren't drawn... I tried adding the CodeFig,CodeFigColor=red, CodeFigStyle=dashed options, but it haven't changed anything... Do you have any ideas ? – EisenHeim May 31 '14 at 9:19
• Not really. You might try to take the LaTeX -> dvips -> pstopdf way. That's what I do when I have problems, as it is easier to see what happens. – Bernard May 31 '14 at 9:29

Just for typing exercise with PSTricks.

\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-plot,pst-eucl}
\psset
{
algebraic,
PointSymbol=none,
saveNodeCoors,
}
\def\y{5*(-x/6+1)}

\begin{document}
\begin{pspicture}(-.5,-.5)(7,6)
\pstGeonode[PosAngle={-135,-90}]{O}(2,0){X_2}(4,0){X_1}
\pstGeonode[PosAngle=45](*N-X_2.x {\y}){a}(*N-X_1.x {\y}){c}
\pstGeonode[PosAngle={45,45,180}](a|c){b}(c|a){d}(0,0|c){P_1}(0,0|a){P_2}
\foreach \pt in {a,...,d}{\psCoordinates[dotsize=0](\pt)}
\psaxes[ticks=none,labels=none](0,0)(6,5)[$X/t$,0][$P/X$,90]
\psplot{1}{5}{\y}
\pcline[nodesepB=-1](a)(d)\ncput[npos=1.4]{$MC=AC$}
\end{pspicture}
\end{document}