How to plot a linear function with axes, arrows, and labels?
\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}
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}