Guide
Guide
August 5, 2021
Wage, W
SW I
Wage-inelastic labor demand
A + B : WT gain
SW E
0 0 G : WT loss
EW E EW I LW I LW E
Wmin Floor
∆W A B E
Wmarket Wage-elastic labor demand
A : WT gain
F + G : WT loss
DW E
C F G
DW I
Labour, Q
0 Q0D,W E Q0D,W I QE Q0L,W I Q0L,W E
∆EW I ∆LW I
∆EW E ∆LW E
∗
If you have any questions, inquiries, or even suggestions on better ways to make graphs, contact
me at [email protected] by email. Do not hesitate to reach out.
1
Contents
1 Introduction 3
1.1 New to LaTeX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 GitHub project repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3 Plotting, colours, and labelling (ex. indifference map and budget constraint) 10
3.1 Plotting functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2 Colours . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.3 Plotting dashed line segments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.4 Plotting coordinate points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.5 Labelling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5 Shading, arrows, and graphs side by side (ex. supply increase, price-taking firm) 29
5.1 Opacity and transparency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.2 Shading in boxes with colours . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.3 Straight and curly arrows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.4 Arranging graphs side by side . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
5.5 Shading in the area under a curve . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
6 Axis dimension lines, line breaks in labels, and a legend (ex. excise tax) 48
6.1 Adding dimension lines and line breaks in labels . . . . . . . . . . . . . . . . . . 51
6.2 Adding a legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
7 Conclusion 59
8 Resources 60
9 Other examples 62
2
1 Introduction
Economics makes an abundant use of graphs to illustrate important concepts and
phenomena. Yet the first thing one may notice when typing up a paper in the field is
the difficulty of making these graphs using word processors. That is where LaTeX
comes in. This guide will explain how we can use the pgfplots package to make
elegant economic graphs in LaTeX.
3
1.3 Packages
We will be using pgfplots to draw economic graphs, so the pgfplots package should
be called. This will call TikZ and xcolor as well. Since we want to be able to shade
in areas under curves, the fillbetween pgfplots library should be called. Since we
want to be able to specify positions around coordinates and use a variety arrowheads
in TikZ, the positioning and arrows.meta TikZ libraries should be called as well.
Also, since we want to be able to use LaTeX’s math mode, we need to call the
amsmath package. In total, we have the following code snippet at the beginning of
the document:
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\usetikzlibrary{positioning, arrows.meta}
\usepgfplotslibrary{fillbetween}
\usepackage{amsmath}
Out of personal preference, we will be using the Times New Roman 12 point font
with a 1.25 line spread (which corresponds to a one-and-a-half line spacing). So we
will be using this document preamble:
\documentclass[12pt]{article}
\linespread{1.25}
\usepackage{times}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\usetikzlibrary{positioning, arrows.meta}
\usepgfplotslibrary{fillbetween}
\usepackage{amsmath}
4
this environment, to construct the pgfplots environment, we insert
\begin{axis} and \end{axis}. Since, presumably, we want the economic
graph to be in the center of the page, all of this should be in the center environment,
with \begin{center} and \end{center} encompassing the code. So we
have:
\begin{center}
\begin{tikzpicture}
\begin{axis}[
% Insert parameters here
]
% Insert commands here
\end{axis}
\end{tikzpicture}
\end{center}
For the axis environment, parameters affect the whole graph (i.e. scaling, axis
ticks, grid lines) while commands impose specific plots (i.e. functions, lines, coor-
dinate points). One thing to note, syntactically, is that parameters are separated by
commas—“,”—while commands are separated by semicolons—“;”.
5
\end{axis}
\end{tikzpicture}
\end{center}
10
0
0 2 4 6 8 10
6
axis lines = left axis lines = center axis lines = right
−1 0 1
1 1 1
0 0
−1 1
−1 −1 −1
−1 0 1
7
Considering the size of the figure on the page, the default size is slightly too
small to present much illustration without cluttering the space available. To slightly
increase the size of the graph, we write the parameter \scale = 1.2. Of course,
if you have a more complex or important illustration, a greater factor can be used to
create bigger graphs. On the other side, a lesser factor can be used to create smaller
graphs. A scale factor of 1.2 occupies about a third of the page.
The last parameter we need to add is clip = false. Normally, pgfplots
cuts off any plots outside the graph, which is useful for automatically bounding
functions. However, we want to be able to put labels outside the graph, so we
disable that feature with this parameter. Instead, we will be manually indicating the
domain and range of plotted functions.
As a reminder, semicolons should be at the end of these lines because they are
commands as opposed to the parameters that have been used thus far.2 For the
demonstration, we will use the x and y-axis labels of $x$ and $y$ respectively.
Putting the dollar signs around the x and y puts them in LaTeX’s math mode (cor-
responding to x and y), allowing us to write the mathematical expressions LaTeX
is known for.
After all of these considerations are addressed, we end up with Figure 2-3:
2
Subsection 3.5: Labelling explains why this command works in more detail.
8
y
x
0
Now the graph is ready to have plots (e.g. functions) drawn upon it. The code that
produces Figure 2-3 is as follows:
\begin{center}
\begin{tikzpicture}
\begin{axis}[
scale = 1.2,
xmin = 0, xmax = 10,
ymin = 0, ymax = 10,
axis lines* = left,
xtick = {0}, ytick = \empty,
clip = false,
]
% Labels
\node [right] at (current axis.right of origin) {$x$};
\node [above] at (current axis.above origin) {$y$};
\end{axis}
\end{tikzpicture}
\end{center}
9
3 Plotting, colours, and labelling (ex. indifference
map and budget constraint)
With our axes, we can begin drawing on the graph. Suppose we wanted to illustrate
why demand is downward-sloping—meaning that quantity demanded falls as price
rises—using indifference curves. More specifically, we want to plot an indifference
map between good A and B with budget constraints showing an increase in the price
of good A corresponding to a decrease in the quantity demanded of the good.
This is a long command. Let us take this in pieces. The addplot parameter of
domain = min:max restricts the function graphed to the domain bounded by
the minimum x-value, min (which is 0 in this case), and maximum x-value, max
(which is 10 in this case). Similarly, restrict y to domain = min:max
restricts the function to the range bounded between min and max (which are 0
and 10 in this case). (Restricting y to a “domain” is a slight misnomer because the
proper mathematical term for the set of y-values is “range.”) Note, the reason why
we need to define the domain and range, as mentioned before, is that we disabled
pgfplots’s clipping feature. The addplot parameter samples = n tells pgfplots
to take a certain number of x-values, n, at which to evaluate the function and draw
a line through all the calculated coordinates. In practice, the higher the number
of samples, the smoother the plotted curve. The last addplot parameter, color
= colour name, is self-explanatory. It colours the line to be the colour name.
Colours are addressed in more detail in the next subsection. In Subsection 3.2:
Colours, there is a list of the predefined colour names along with an explanation on
how to add more predefined colour sets and define new colour names.
Moving on to the mathematical expression within the curly braces, this is where
10
10
we put the function’s expression, x2
+1. It is important to note that the conventional
notation of juxtaposition (placing numbers and letters side by side) for multiplica-
tion throws an error. Instead, an asterisk—“*”—can only indicate multiplication.
Otherwise, conventional computer notation applies, with addition, subtraction, di-
vision, and grouping represented by “+”, “-”, “/”, and “( )” respectively. Plotting
the aforementioned command yields Figure 3-1.
A
0
11
\addplot[domain = 0:10, restrict y to domain = 0:10, samples =
400, color = red]{10/(x^2)+1};
% Labels
\node [right] at (current axis.right of origin) {$A$};
\node [above] at (current axis.above origin) {$B$};
\end{axis}
\end{tikzpicture}
\end{center}
One thing to notice about Figure 3-1 and its code is that the x-axis label is A and the
y-axis label is B. This is because, in this example, we want to show that an increase
in the price of good A causes a decrease in the quantity demanded of the good.
Naturally, an indifference map contains more than one curve. So, let us plot
multiple curves by translating the first curve to the right by one unit and up by
one unit. In transformation notation, this corresponds to (x, y) → (x − 1, y + 1).
10
Transforming the first curve, U1 : B = A2
+ 1, results in the second curve, U2 :
10 10
B = (A−1)2
+ 2. Repeating this transformation results in, U3 : B = (A−2)2
+ 3,
10 10
U4 : B = (A−3)2
+ 4, and U5 : B = (A−4)2
+ 5. Plotting all five of these curves
yields Figure 3-2.
B
A
0
12
The indifference curves in Figure 3-2 are plotted by the following code snippet:
% Indifference curves
\addplot[domain = 0:10, restrict y to domain = 0:10, samples =
400, color = red]{10/(x^2)+1};
\addplot[domain = 1:10, restrict y to domain = 0:10, samples =
400, color = red]{10/((x-1)^2)+2};
\addplot[domain = 2:10, restrict y to domain = 0:10, samples =
400, color = red]{10/((x-2)^2)+3};
\addplot[domain = 3:10, restrict y to domain = 0:10, samples =
400, color = red]{10/((x-3)^2)+4};
\addplot[domain = 4:10, restrict y to domain = 0:10, samples =
400, color = red]{10/((x-4)^2)+5};
Note that the domain restrictions are different for each function. U1 is restricted to
A ∈ (0, 10), while U2 is restricted to A ∈ (1, 10), and U3 is restricted to A ∈ (2, 10),
and so on. The reason for this is because each indifference curve’s equation has
different vertical asymptotes, with it being A = 0 for U1 , A = 1 for U2 , and A = 2
for U3 , etc. Because we only care about the graph of the equation at the right-hand
side of the vertical asymptote, we restrict the utility functions to the domain right
of the vertical asymptote. Figure 3-3 illustrates this domain restriction.
A A
0 0
Figure 3-3: Restricting the domain of an indifference curve.
Now that we have the indifference map plotted, we need to plot the changing
budget constraints in response to a rise in the price of good A. In effect, this means
13
two diagonal lines: one from a positive B-intercept to a positive A-intercept, and
another line from that B-intercept to a reduced positive A-intercept. This represents
the change in the maximum number of good A that can be bought because of a price
increase, while the maximum number of good B remains the same. In addition,
because we want to show the change in the consumer decisions after a constriction
in budget constraint, the two budget constraints must be tangent to indifference
curves. We will use U3 to be tangent to the original budget constraint at A = 4.7 and
U2 to be tangent to the new one at A = 3.3. The original and new budget constraints
are calculated to be the equations B = 9.16 − 1.02A and B = 9.16 − 1.59A
respectively (these are approximations of the actual tangents). Logistically, the
equations of these budget constraints can be calculated or approximated beforehand,
manually or with software such as WolframAlpha or Desmos.3 Using the same
addplot command which we used previously to plot the lines of the indifference
curves, we can plot the two budget constraints.
Lastly, to make the budget constraint lines stand out in the midst of the indiffer-
ence map, we need to thicken them. This is done by adding the parameter thick to
the addplot. The preset line thicknesses are ultra thin, very thin, thin,
thick, very thick, or ultra thick—or we could define our own thickness
with the line width = width parameter where width is in units of length.
In total, we have the following code snippet for the budget constraint lines:
% Budget constraints
\addplot[domain = 0:10, restrict y to domain = 0:10, samples =
400, color = blue, thick]{9.16-1.02*x};
\addplot[domain = 0:10, restrict y to domain = 0:10, samples =
400, color = blue, thick]{9.16-1.59*x};
14
B
A
0
3.2 Colours
In the previous subsection, we used two colours—red and blue—to draw functions.
You might be wondering how many colours we can use, or how to define new
colours. Remember, we called the xcolor package because it expands LaTeX’s
limited base capacities to manipulate and use colours.
There are 19 default colours predefined by LaTeX:
red ( ), green ( ), blue ( ), cyan ( ), magenta ( ), yellow ( ), black ( ),
gray ( ), white ( ), darkgray ( ), lightgray ( ), brown ( ), lime ( ), olive ( ),
orange ( ), pink ( ), purple ( ), teal ( ), and violet ( ).4
We already saw red and blue in the previous subsection. Although limited, the
default colour palette is diverse enough for this guide.
4
By the way, in case you are wondering how I am producing these coloured
squares, I explain how in Subsection 6.2: Adding a legend. The command
\fcolorbox{black}{red}{\textcolor{red}{\rule{\fontcharht\font`X}
{\fontcharht\font`X}}} produces .
15
However, if these colours are too limited, xcolor comes with a variety of options
that defines more colours. For example, the dvipsnames option defines 68 more
colours:
Apricot ( ), Aquamarine ( ), Bittersweet ( ), Black ( ), Blue ( ), Blue-
Green ( ), BlueViolet ( ), BrickRed ( ), Brown ( ), BurntOrange ( ), Cadet-
Blue ( ), CarnationPink ( ), Cerulean ( ), CornflowerBlue ( ), Cyan ( ), Dan-
delion ( ), DarkOrchid ( ), Emerald ( ), ForestGreen ( ), Fuchsia ( ), Golden-
rod ( ), Gray ( ), Green ( ), GreenYellow ( ), JungleGreen ( ), Lavender ( ),
LimeGreen ( ), Magenta ( ), Mahogany ( ), Maroon ( ), Melon ( ), Mid-
nightBlue ( ), Mulberry ( ), NavyBlue ( ), OliveGreen ( ), Orange ( ), Oran-
geRed ( ), Orchid ( ), Peach ( ), Periwinkle ( ), PineGreen ( ), Plum ( ), Pro-
cessBlue ( ), Purple ( ), RawSienna ( ), Red ( ), RedOrange ( ), RedViolet ( ),
Rhodamine ( ), RoyalBlue ( ), RoyalPurple ( ), RubineRed ( ), Salmon ( ), Sea-
Green ( ), Sepia ( ), SkyBlue ( ), SpringGreen ( ), Tan ( ), TealBlue ( ), This-
tle ( ), Turquoise ( ), Violet ( ), VioletRed ( ), White ( ), WildStrawberry ( ),
Yellow ( ), YellowGreen ( ), and YellowOrange ( ).
It is important to note that these colour names are case-sensitive. Meaning that
color = violet ( ) is different from color = Violet ( ), and color = VIOLET
will throw an error.
To add the dvipsnames colour palette, we call the xcolor package with the
dvipsnames option, so, \usepackage[dvipsnames]{xcolor}. If the usep-
ackage command is called after pgfplots’s, an error will be thrown. This is be-
cause TikZ calls xcolor by default and clashes with this new usepackage com-
mand. So make sure that the xcolor package is called before the TikZ package.
Alternatively, if this does not work, then we could add the parameter xcolor =
{dvipsnames} to the document class command. For us, we would use,
\documentclass[12pt, xcolor = {dvipsnames}] {article}.
There are other palettes aside from dvipsnames, such as svgnames, which de-
fines 151 colours, or x11names which defines 317 colours. In addition, new colours
can be manually defined using the command \definecolor{name}{model}
{variable 1, variable 2, variable 3}, where the model is either
rgb, HTML, cmyk, among others. For example, a light tan colour can be defined by
16
\definecolor {name}{rgb}{0.95, 0.95, 0.92} ( ).5
A lot can be done with colours in LaTeX. We can colour text, have background
colours, and make the page colour different from the standard white (though that
would be ill advised, considering the strain on printers). Most of these are outside
the scope of this guide and so will not be covered. Resources are available at Section
8: Resources, which includes documentation and guides on the xcolor package.
As seen, the coordinates the line goes through should be listed within the curly
braces. Also, because we want the line to be dashed, we include the parameter
dashed. The other two parameters, color = black and thick have already
been covered in the previous subsections. They respectively colour the resulting line
black and make its line width thicker. Repeating this process for the new decision
point at (3.3, 3.9) yields Figure 3-5.
5
Incidentally, this is what I use as the background colour of the code snippets in this guide.
17
B
A
0
18
B
A
0
3.5 Labelling
Finally, to finish the graph we need to label all the relevant parts of it. Specifically,
we need to put letters near the A and B-intercepts, the coordinate points, and the
ends of the functions. To label a part of the graph, the command takes the form of:
\node [position] at (coordinate) {label};
This command will place some text, the label, next to the coordinate specified. In
addition, where the label ends up near the coordinate depends on the position, it
can either be left, right, above, or below the coordinate. For instance, to
put a label of QA below (4.7, 0), where the dashed line extending downward from
the original decision point meets the A-axis, we write the following command:
\node [below] at (4.7, 0) {$Q_A$};
We have already used a form of the node command previously when labelling
our axes. Notice, however, that the coordinate point for an axis label is different
because it refers to the end of an axis. Using the labelling command to label the
rest of the graph, such as the functions and coordinates, we end up with Figure 3-7.
19
B
U5
QB D
U4
Q0B
D0 U3
U2
U1
0
M M
A
0 Q0A QA
Figure 3-7: The effect of an increase in the price of good A on the budget constraint
and indifference map between good A and good B.
Finally, we have completed the indifference map illustrating why demand slopes
downward. It is because Q0A is less than QA when the budget shifts from M to
M 0 . More importantly, we illustrated this in LaTeX! Figure 3-7 is produced by the
following code, combining all of the elements covered in this section:
\begin{center}
\begin{tikzpicture}
\begin{axis}[
scale = 1.2,
xmin = 0, xmax = 10,
ymin = 0, ymax = 10,
axis lines* = left,
xtick = {0}, ytick = \empty,
clip = false,
]
% Indifference curves
\addplot[domain = 0:10, restrict y to domain = 0:10, samples =
400, color = red]{10/(x^2)+1};
20
\addplot[domain = 1:10, restrict y to domain = 0:10, samples =
400, color = red]{10/((x-1)^2)+2};
\addplot[domain = 2:10, restrict y to domain = 0:10, samples =
400, color = red]{10/((x-2)^2)+3};
\addplot[domain = 3:10, restrict y to domain = 0:10, samples =
400, color = red]{10/((x-3)^2)+4};
\addplot[domain = 4:10, restrict y to domain = 0:10, samples =
400, color = red]{10/((x-4)^2)+5};
% Budget constraints
\addplot[domain = 0:10, restrict y to domain = 0:10, samples =
400, color = blue, thick]{9.16-1.02*x};
\addplot[domain = 0:10, restrict y to domain = 0:10, samples =
400, color = blue, thick]{9.16-1.59*x};
% Dashed lines
\addplot[color = black, dashed, thick] coordinates {(4.7, 0) (4.7,
4.37) (0, 4.37)};
\addplot[color = black, dashed, thick] coordinates {(3.3, 0) (3.3,
3.9) (0, 3.9)};
% Coordinate points
\addplot[color = black, mark = *, only marks, mark size = 3pt]
coordinates {(3.3, 3.9) (4.7, 4.37)};
% Labels
\node [right] at (current axis.right of origin) {$A$};
\node [above] at (current axis.above origin) {$B$};
\node [above] at (9.1, 0) {$M$};
\node [above] at (6, 0) {$M^\prime$};
\node [below] at (4.7, 0) {$Q_A$};
\node [below] at (3.3, 0) {$Q_A^\prime$};
\node [left] at (0, 4.5) {$Q_B$};
\node [left] at (0, 3.7) {$Q_B^\prime$};
\node [above] at (5.1, 4.2) {$D$};
\node [above] at (2.9, 2.8) {$D^\prime$};
\node [right] at (10, 1.1) {$U_1$};
\node [right] at (10, 2.12) {$U_2$};
21
\node [right] at (10, 3.16) {$U_3$};
\node [right] at (10, 4.2) {$U_4$};
\node [right] at (10, 5.4) {$U_5$};
\end{axis}
\end{tikzpicture}
\end{center}
22
Price, P
E
PE
D
Widgets, Q
0 QE
Figure 4-1: The market equilibrium for the widget market (on a blank graph).
The elements in Figure 4-1 have been explained in previous sections. It is pro-
duced by the following code:
\begin{center}
\begin{tikzpicture}
\begin{axis}[
scale = 1.2,
xmin = 0, xmax = 10,
ymin = 0, ymax = 10,
axis lines* = left,
xtick = {0}, ytick = \empty,
clip = false,
]
% Supply and demand curves
\addplot[color = blue, very thick] coordinates {(1, 9) (9, 1)};
\addplot[color = red, very thick] coordinates {(1, 1) (9, 9)};
% Dashed lines
\addplot[color = black, dashed, thick] coordinates {(0, 5) (5, 5)
(5, 0)};
23
% Coordinate points
\addplot[color = black, mark = *, only marks, mark size = 3pt]
coordinates {(5, 5)};
% Labels
\node [right] at (current axis.right of origin) {Widgets, $Q$};
\node [above] at (current axis.above origin) {Price, $P$};
\node [above] at (5, 5.2) {$E$};
\node [left] at (0, 5) {$P_E$};
\node [below] at (5, 0) {$Q_E$};
\node [right] at (9, 1) {$D$};
\node [right] at (9, 9) {$S$};
\end{axis}
\end{tikzpicture}
\end{center}
24
where the number is the number of minor ticks. In this case, we want one minor
tick halfway between the major ticks—otherwise it would be too cluttered—so the
number of minor ticks is 1. Moreover, we want the major grid lines to be solid lines
and the minor grid lines to be dotted lines. This way, half and full increments are vi-
sually evident. To change the style of major and minor grid lines to solid and dotted
lines, we use grid style = solid and minor grid style = dotted
respectively. More styles include dashed, thin, and thick. Defining the grid
style to be solid is redundant since that is the default, but I have opted to make it
explicit. So far we have added, or modified, the parameters in the following code
snippet:
xtick = {0,1,2,3,4,5,6,7,8,9,10},
ytick = {0,1,2,3,4,5,6,7,8,9,10},
grid = both,
minor tick num = 1,
grid style = solid,
minor grid style = dotted,
This snippet adds axis ticks from 1 to 10 in increments of 1 on both the x and y
axes. In addition, it shows both the minor and major grid lines, sets the number
of minor ticks between major ticks to one tick, and makes major grid lines solid
lines and minor grid lines dotted lines. Using these parameters to the blank market
equilibrium graph results in Figure 4-2.
25
Price, P
10
9 S
8
7
6
E
PE5
4
3
2
1 D
0 Widgets, Q
0 1 2 3 4 Q5E 6 7 8 9 10
Ah! That is ugly! While we got the axis ticks and grid lines we were seeking,
this caused other issues for the legibility of this graph. Specifically, the labels of
QE and PE need to be moved away from the axis numbers, the axis labels should
be moved slightly away from the graph, and the labels of E, S, and D need to
have white backgrounds to reduce clutter. In addition, there are two zeros at the
origin—one is enough.
While the position does a good job in most situations of determining how far the
label should be from the coordinate, sometimes we want to increase this distance. In
such situations, the distance can be specified with position = distance. So,
26
for example, the position for QE can be changed to below = 10pt. Repeating
this for the PE label, we have the following code snippet:
\node [left = 10pt] at (0, 5) {$P_E$};
\node [below = 10pt] at (5, 0) {$Q_E$};
Moving on to the latter issues. Getting rid of the y-axis label of 0 and moving
the axis labels can both be done by changing the domain and range of the graph
shown. To get rid of the 0 on the y-axis, we define the minimum of the range to
be 0.01 (any very small number suffices, though this varies depending on the order
of magnitude of the data). So we have ymin = 0.01 as an axis parameter. To
distance the axis labels, the maximums of both the domain and range should be
extended to 10.5 (this too varies depending on the order of magnitude). In sum, we
have the following code snippet:
xmin = 0, xmax = 10.5,
ymin = 0.01, ymax = 10.5,
Finally, we want to colour the background of labels on the graph white. Other-
wise, we would be stuck with lines cutting through E, S, and D, which does not
look good. This also involves a relatively simple adjustment. We add the parameter
fill = white to the node commands of the labels. The code snippet for the
changed labels are:
\node [above = 5pt, fill = white] at (5, 5.2) {$E$};
\node [right, fill = white] at (9, 1) {$D$};
\node [right, fill = white] at (9, 9) {$S$};
The label of E has also been distanced by 5 pt using the positioning parameter as
explained in the preceding paragraph. This was done to avoid covering the supply
and demand lines with the white background. There are other ways to resolve this
inconvenience. For example, because pgfplots layers these plots sequentially—
where later commands cover previous ones—simply having the node command for
the label above the ones for the supply and demand line curves could work. That
way, the commands for the supply and demand curves would be executed after the
label and would cover up the white background.
Combining all of these adjustments, we end up with Figure 4-3.
27
Price, P
10
9 S
8
7
6 E
PE 5
4
3
2
1 D
Widgets, Q
0 1 2 3 4 5 6 7 8 9 10
QE
And so we have finished adjusting the blank graph to one with ticks and grid lines
so that it can accommodate empirical data and represent specific values. The code
for Figure 4-3 is:
\begin{center}
\begin{tikzpicture}
\begin{axis}[
scale = 1.2,
xmin = 0, xmax = 10.5,
ymin = 0.01, ymax = 10.5,
axis lines* = left,
xtick = {0,1,2,3,4,5,6,7,8,9,10},
ytick = {0,1,2,3,4,5,6,7,8,9,10},
grid = both,
minor tick num = 1,
grid style = solid,
minor grid style = dotted,
clip = false,
]
28
% Supply and demand curves
\addplot[color = blue, very thick] coordinates {(1, 9) (9, 1)};
\addplot[color = red, very thick] coordinates {(1, 1) (9, 9)};
% Dashed lines
\addplot[color = black, dashed, thick] coordinates {(0, 5) (5, 5)
(5, 0)};
% Coordinate points
\addplot[color = black, mark = *, only marks, mark size = 3pt]
coordinates {(5, 5)};
% Labels
\node [right] at (current axis.right of origin) {Widgets, $Q$};
\node [above] at (current axis.above origin) {Price, $P$};
\node [above = 5pt, fill = white] at (5, 5.2) {$E$};
\node [left = 10pt] at (0, 5) {$P_E$};
\node [below = 10pt] at (5, 0) {$Q_E$};
\node [right, fill = white] at (9, 1) {$D$};
\node [right, fill = white] at (9, 9) {$S$};
\end{axis}
\end{tikzpicture}
\end{center}
29
Price, P
S
S0
PE E
P0 E0
D
Farm products, Q
0 QE Q0
Figure 5-1: The effect of a bumper harvest on the farm product market.
Figure 5-1 is graphed using the tools already explained in the sections above.
The code is as follows:
\begin{center}
\begin{tikzpicture}
\begin{axis}[
scale = 1.2,
xmin = 0, xmax = 10,
ymin = 0, ymax = 10,
axis lines* = left,
xtick = {0}, ytick = \empty,
clip = false,
]
% Supply and demand curves
\addplot[color = blue, very thick] coordinates {(5,9) (8,1)};
\addplot[color = red, very thick] coordinates {(3,1) (6,9)};
\addplot[color = red, very thick] coordinates {(6,1) (9,9)};
% Dashed lines
30
\addplot[color = black, dashed, thick] coordinates {(0, 7.67)
(5.5, 7.67) (5.5, 0)};
\addplot[color = black, dashed, thick] coordinates {(0, 3.67) (7,
3.67) (7, 0)};
% Coordinate points
\addplot[color = black, mark = *, only marks, mark size = 3pt]
coordinates {(5.5, 7.67) (7, 3.67)};
% Labels
\node [right] at (current axis.right of origin){Farm products, $Q
$};
\node [above] at (current axis.above origin) {Price, $P$};
\node [right] at (5.5, 7.67) {$E$};
\node [right] at (7, 3.67) {$E^\prime$};
\node [right] at (8, 1) {$D$};
\node [above] at (6, 9) {$S$};
\node [right] at (9, 9) {$S^\prime$};
\node [left] at (0, 7.67) {$P_E$};
\node [left] at (0, 3.67) {$P^\prime$};
\node [below] at (5.5, 0) {$Q_E$};
\node [below] at (7, 0) {$Q^\prime$};
\end{axis}
\end{tikzpicture}
\end{center}
31
Price, P
S
S0
PE E
P0 E0
D
Farm products, Q
0 QE Q0
Figure 5-2: Making the new supply curve on the graph more transparent.
32
\fill[colour name] (A) -- (B) -- (C) -- ...;
In this command, (A), (B), (C), . . . , are an indefinite number of coordinates. The
command colours in the polygon defined by the coordinates with the specified
colour. Looking at the graph, the original equilibrium point is (5.5, 7.67) and the
new equilibrium point is (7, 3.67). Meaning that, for the loss area, we need to colour
in orange the square defined by the coordinates (0, 7.67), (0, 3.67), (5.5, 3.67), and
(5.5, 7.67). Similarly, we shade green the gain area defined by the coordinates (5.5,
0), (5.5, 3.67), (7, 3.67), and (7, 0). So far, we have the following code snippet:
\fill[orange] (0, 7.67) -- (0, 3.67) -- (5.5, 3.67) -- (5.5, 7.67)
;
\fill[green] (5.5, 0) -- (5.5, 3.67) -- (7, 3.67) -- (7, 0);
Since we want these coloured areas to be unobtrusive, the colours need to be mostly
transparent. This can be done the same way it is done to plots as shown in the pre-
vious subsection, Subsection 5.1: Opacity and transparency, either through TikZ’s
opacity parameter or through xcolor’s exclamation mark notation. So the snippet
the graph will be using is:
\fill[orange, opacity = 0.1] (0, 7.67) -- (0, 3.67) -- (5.5, 3.67)
-- (5.5, 7.67);
\fill[green, opacity = 0.1] (5.5, 0) -- (5.5, 3.67) -- (7, 3.67)
-- (7, 0);
Unfortunately, we cannot simply put these commands into the axis environment.
There are a couple considerations to address so that these coloured areas do not
interfere and overlap with other features on the graph. Because pgfplots processes
commands sequentially so that later plots are layered upon earlier plots, the fill
commands should precede every other one—otherwise the coloured areas could
cover up another part of the graph. Also, since fill commands cannot precede the
axis parameters, the axis parameter axis on top should be added. This ensures
that the axis lines are not covered up by plots and other commands. The coloured
areas are shown in Figure 5-3.
33
Price, P
S
S0
PE E
P0 E0
D
Farm products, Q
0 QE Q0
This command draws an arrow starting from (A) and ending at (B). The tip of the
arrow at B is specified by the arrowhead value. TikZ has a limited array of
arrowheads to choose from, so that is why we loaded the arrows.meta TikZ
library in Subsection 1.3: Packages. With this library, we have access to more
34
arrowheads such as Triangle, Circle, Square, Diamond, and so on, all of
which are self-descriptive. The Triangle arrowhead is the most appropriate to
show the shift from the original to the new supply curves.
Using this command, we will draw an arrow from the right of the original supply
curve to the left of the new supply curve. This corresponds to an arrow from (6.3,
8.5) to (8.3, 8.5) with an arrowhead of Triangle. So we have the following code
snippet:
\draw[-Triangle] (6.3, 8.5) to (8.3, 8.5);
While this will do the job, there are a couple changes we should make to improve
the aesthetics and readability of the arrow. First, it would be better if the arrow was
a mostly transparent red to show it is modifying the supply curve. Conveniently,
this is just like filling areas with colours and colouring plots as we have done in
before. We write red, opacity = 0.3 as parameters to the draw command
for the arrow. Second, arrowheads are small by default. We would like to make
the supply curve shift arrow slightly bigger. This is slightly harder to do. To begin
with, we surround the arrowhead value with curly braces to indicate that we are
using a custom arrowhead. So we have -{Triangle}. Then, as parameters to
the arrowhead value we add the parameters length = 4mm, width = 2mm
which modify the dimensions of the arrowhead. Accordingly, we have the final
code snippet for the supply shift arrow:
\draw[-{Triangle[length = 4mm, width = 2mm]}, red, opacity = 0.3]
(6.3, 8.5) to (8.3, 8.5);
Using this command to draw the arrow upon the graph results in Figure 5-4.
35
Price, P
S
S0
PE E
P0 E0
D
Farm products, Q
0 QE Q0
Figure 5-4: Drawing a straight line from the original supply curve to the new one.
Next, we will label the gain and loss areas. Simply putting a vertical arrow from
below the x-axis to the green area would be too cluttered. We would have the labels
Q, Q0 , and an arrow all sharing that small space. Instead, let us draw a curly arrow
pointing from the bottom-right of the axis to the centre of the green area curving in
a counterclockwise direction so that it avoids the Q and Q0 labels. Curly arrows are
drawn with a draw command in the form of:
\draw[-arrowhead] (A) to [out = out angle, in = in angle] (B);
Notice that this is nearly identical to the command for straight arrows, except for
one addition. Within the square brackets after the “to”, the parameters specify the
angles from the starting coordinate and to the ending coordinate which the line for
the curve should be drawn. They are given in arc degrees, meaning from 0 for right,
to 90 for up, to 180 for left, to 270 for down, to 360 for right again, and everything
in between. I have found beforehand that the starting coordinate for the curly arrow
is (10, -1.5) and the ending coordinate is (6.5, 0.7). Since the arrow should spring
forth upward from the starting coordinate and comes into the ending coordinate
from the right, the out angle is 90 and the in angle is 0. And so the code snippet
36
producing the curly arrow pointing at the gain area is:
\draw[-Triangle] (10, -1.5) to [out = 90, in = 0] (6.5, 0.7);
Repeating this for the loss area, for an arrow from the top to the orange box, and
adding text labels (which was covered in Subsection 3.5: Labelling), we have this
code snippet:
% Labels
\node [right] at (5, 11) {Total revenue lost};
\node [above] at (10, -3) {Total revenue gained};
% Arrows
\draw[-Triangle] (5, 11) to [out = 180, in = 90] (2, 6);
\draw[-Triangle] (10, -1.5) to [out = 90, in = 0] (6.5, 0.7);
PE E
P0 E0
D
Farm products, Q
0 QE Q0
Figure 5-5: The bumper harvest paradox: why farmers’ revenues decrease after a
large harvest.
37
Figure 5-5 is produced by the following code:
\begin{center}
\begin{tikzpicture}
\begin{axis}[
scale = 1.2,
xmin = 0, xmax = 10,
ymin = 0, ymax = 10,
axis lines* = left,
xtick = {0}, ytick = \empty,
axis on top,
clip = false,
]
% Colouring areas
\fill[orange, opacity = 0.1] (0, 7.67) -- (0, 3.67) -- (5.5, 3.67)
-- (5.5, 7.67);
\fill[green, opacity = 0.1] (5.5, 0) -- (5.5, 3.67) -- (7, 3.67)
-- (7, 0);
% Dashed lines
\addplot[color = black, dashed, thick] coordinates {(0, 7.67)
(5.5, 7.67) (5.5, 0)};
\addplot[color = black, dashed, thick] coordinates {(0, 3.67) (7,
3.67) (7, 0)};
% Coordinate points
\addplot[color = black, mark = *, only marks, mark size = 3pt]
coordinates {(5.5, 7.67) (7, 3.67)};
% Labels
\node [right] at (current axis.right of origin){Farm products, $Q
$};
38
\node [above] at (current axis.above origin) {Price, $P$};
\node [right] at (5.5, 7.67) {$E$};
\node [right] at (7, 3.67) {$E^\prime$};
\node [right] at (8, 1) {$D$};
\node [above] at (6, 9) {$S$};
\node [right] at (9, 9) {$S^\prime$};
\node [left] at (0, 7.67) {$P_E$};
\node [left] at (0, 3.67) {$P^\prime$};
\node [below] at (5.5, 0) {$Q_E$};
\node [below] at (7, 0) {$Q^\prime$};
\node [right] at (5, 11) {Total revenue lost};
\node [above] at (10, -3) {Total revenue gained};
% Arrows
\draw[-{Triangle[length = 4mm, width = 2mm]}, red, opacity = 0.3]
(6.3, 8.5) to (8.3, 8.5);
\draw[-Triangle] (5, 11) to [out = 180, in = 90] (2, 6);
\draw[-Triangle] (10, -1.5) to [out = 90, in = 0] (6.5, 0.7);
\end{axis}
\end{tikzpicture}
\end{center}
39
Total economic profit lost
Price, p MC M C0
AT C
PE MR
e
0
e0
P M R0
AT C 0
Farm products, q
0 qe q0
The above graph is produced entirely with the tools and techniques already covered
in previous sections. It is a combination of plots, coordinate points, labels, colours
and transparency, and so on. Figure 5-6 is produced by the following code:
\begin{center}
\begin{tikzpicture}
\begin{axis}[
scale = 1.2,
xmin = 0, xmax = 10,
ymin = 0, ymax = 10,
axis lines* = left,
xtick = {0}, ytick = \empty,
axis on top,
clip = false,
]
40
% Colouring areas
\fill[orange, opacity = 0.1] (0, 3.67) -- (3.68, 3.67) -- (3.68,
7.67) -- (0, 7.67);
\fill[green, opacity = 0.1] (3.68, 1) -- (5.45, 1) -- (5.45, 3.67)
-- (3.68, 3.67);
\fill[green, opacity = 0.1] (0, 1) -- (0, 2) -- (3.68, 2) --
(3.68, 1);
% Curves
\addplot [domain = 1:10, restrict y to domain = 0:10, samples =
400, color = blue, very thick] {(x-1)^2+0.5};
\addplot [domain = 1:10, restrict y to domain = 0:10, samples =
400, color = blue, opacity = 0.3, very thick] {(0.4*(x-1))
^2+0.5};
\addplot [domain = 1:10, restrict y to domain = 0:10, samples =
400, color = red, very thick] {(0.55*(x-5))^2+1.5};
\addplot [domain = 1:10, restrict y to domain = 0:10, samples =
400, color = red, opacity = 0.3, very thick] {(0.15*(x-5))^2+1
};
\addplot [domain = 0:10, restrict y to domain = 0:10, samples =
400, color = teal, very thick] {7.67};
\addplot [domain = 0:10, restrict y to domain = 0:10, samples =
400, color = teal, opacity = 0.3, very thick] {3.67};
% Dashed lines
\addplot[color = black, dashed, thick] coordinates {(3.68, 0)
(3.68, 7.67)};
\addplot[color = black, dashed, thick] coordinates {(5.45, 0)
(5.45, 3.67)};
\addplot[color = black, dashed, thick] coordinates {(0, 1) (5.45,
1)};
\addplot[color = black, dashed, thick] coordinates {(0, 2) (3.68,
2)};
% Coordinate points
\addplot[color = black, mark = *, only marks, mark size = 3pt]
coordinates {(3.68, 7.67)(5.45, 3.67)};
41
% Labels
\node [right] at (current axis.right of origin){Farm products, $q
$};
\node [above] at (current axis.above origin) {Price, $p$};
\node [below right] at (3.68, 7.67) {$e$};
\node [above left] at (5.45, 3.67) {$e^\prime$};
\node [above] at (4, 10) {$MC$};
\node [above] at (10, 9) {$ATC$};
\node [right] at (10, 7.8) {$MR$};
\node [above] at (8.7, 10) {$MC^\prime$};
\node [right] at (10, 1.56) {$ATC^\prime$};
\node [right] at (10, 3.67) {$MR^\prime$};
\node [left] at (0, 7.67) {$P_E$};
\node [left] at (0, 3.67) {$P^\prime$};
\node [below] at (3.68, 0) {$q_e$};
\node [below] at (5.45, 0) {$q^\prime$};
\node [above] at (2, 12) {Total economic profit lost};
\node [above] at (3, -3) {Total economic profit gained};
% Arrows
\draw[-Triangle] (3, -1.5) to [in = 180, out = 90] (5, 2);
\draw[-Triangle] (3, -1.5) to (3, 1.7);
\draw[-Triangle] (2, 12) to (2, 6.5);
\end{axis}
\end{tikzpicture}
\end{center}
We want it arranged such that the market equilibrium graph (Figure 5-5) is on
the left-hand side of a panel while the price-taking firm (Figure 5-6) is on the right-
hand side. Surprisingly, this is actually very simple. All we need to do is create
another axis environment right after the first one, but still within the same tikzpic-
ture environment. This will overlay the two graphs on top of each other. Then,
we add the parameter shift = (axis cs: x-shift, y-shift) to the
second axis environment where the x and y-shifts are the amounts by which the
second graph will be moved away from its original position. Since we want to shift
the second graph (the price-taking firm) to the right of the first graph (the market
equilibrium), we will use an x-shift of 17 and a y-shift of 0. So we have:
42
\begin{center}
\begin{tikzpicture}
\begin{axis}[
% Insert parameters for Graph 1
]
% Insert commands for Graph 1
\end{axis}
\begin{axis}[
% Insert parameters for Graph 2
shift = {(axis cs: 17, 0)},
]
% Insert commands for Graph 2
\end{axis}
\end{tikzpicture}
\end{center}
Finally, we need to make an adjustment to fit the figure on the page. Since the
figure’s width is greater than what the page margins allow, we tell TikZ to dis-
regard the page margins by widening the picture frame. To do this, we write
\hspace*{-3cm} before the \begin{tikzpicture} and after the
\end{tikzpicture} which widens the picture’s frame to the left by 3 cm and
to the right by 3 cm respectively. In total, putting all of this together yields Figure
5-7.
43
Total economic profit lost
E0 e0
P0 P0 M R0
AT C 0
D
Farm products, Q Farm products, q
0 QE Q0 0 qe q0
Total revenue gained Total economic profit gained
Figure 5-7: The effect of a bumper harvest on the farm product market (L) and
individual farmers (R).
The code is executed using the commands and parameters that produce Figures 5-5
44
and 5-6 for Graphs 1 and 2 respectively.6
A
0
6
I will not include the full code for Figure 5-7 as it is too long and repeats the code snippets that
were shown for Figures 5-5 and 5-6. Instead, the code that produces Figure 5-7 can be accessed on
the GitHub repository: https://github.com/jackypacky/pgf-econ-graphs.
45
\begin{axis}[
scale = 1.2,
xmin = 0, xmax = 10,
ymin = 0, ymax = 10,
axis lines* = left,
xtick = {0}, ytick = \empty,
clip = false,
]
% Production-possibility frontier
\addplot [domain = 0:10, restrict y to domain = 0:10, samples =
10000, color = blue, very thick] {(49-x^2)^0.5};
% Labels
\node [right] at (current axis.right of origin){$A$};
\node [above] at (current axis.above origin) {$B$};
\end{axis}
\end{tikzpicture}
\end{center}
To shade in areas between two functions, we use a command that takes the form
of:
\addplot [parameters] fill between [of = f and g];
where parameters are the parameters which modify the addplot command, and
f and g are the name paths of the functions. For the parameters, we will use blue,
and opacity = 0.1 which creates a transparent blue similar to what we did in
Subsection 5.1: Opacity and transparency.
To input the name paths f and g, however, we first need to define the name
paths beforehand. To define the name path of a curve, we add the parameter name
path = label to the addplot command where label is the name we want to
assign it. So we will use the addplot parameter name path = frontier for
the command which plots the production-possibility curve. Since we need another
function between which we can shade in the area, and since we want to shade the
area under the curve, we need to plot a new curve defined by the equation y = 0
and name it axis. For this new axis curve, we add the addplot parameter line
width = 0pt to make it invisible—since we do not want it to show up on the
46
graph.
In total, shading in the area under the production-possibility curve is shown in
Figure 5-9.
A
0
47
\addplot [domain = 0:10, restrict y to domain = 0:10, line width =
0pt, name path = axis] {0};
% Colouring areas
\addplot [blue, draw = none, fill opacity = 0.1] fill between [of
= frontier and axis];
% Labels
\node [right] at (current axis.right of origin){$A$};
\node [above] at (current axis.above origin) {$B$};
\end{axis}
\end{tikzpicture}
\end{center}
48
Price, P
S0
E0
0 S
P
A
PE C E
PS F
B
D
Gasoline, Q
0 Q0 QE
49
3.53);
% Dashed lines
\addplot[color = black, dashed, thick] coordinates {(0, 5.96)
(4.14, 5.96) (4.14, 0)};
\addplot[color = black, dashed, thick] coordinates {(0, 3.53)
(5.05, 3.53) (5.05, 0)};
\addplot[color = black, dashed, thick] coordinates {(0, 3) (4.1,
3)};
% Coordinate points
\addplot[color = black, mark = *, only marks, mark size = 3pt]
coordinates {(4.14, 5.96) (5.05, 3.53)};
% Labels
\node [right] at (current axis.right of origin){Gasoline, $Q$};
\node [above] at (current axis.above origin) {Price, $P$};
\node [above] at (5.25, 3.6) {$E$};
\node [above] at (4.35, 6.1) {$E^\prime$};
\node [right] at (6, 1) {$D$};
\node [right] at (9, 6) {$S$};
\node [right] at (9, 9) {$S^\prime$};
\node [left] at (0, 3.7) {$P_E$};
\node [left] at (0, 2.8) {$P_S$};
\node [left] at (0, 5.96) {$P^\prime$};
\node [below] at (5.05, 0) {$Q_E$};
\node [below] at (4.14, 0) {$Q^\prime$};
\node [above] at (2, 4.7) {$A$};
\node [above] at (1, 2) {$B$};
\node [above] at (4.5, 3.5) {$C$};
\node [above] at (6.2, 2.2) {$F$};
50
% Arrows
\draw[-{Triangle[length=4mm, width=2mm]}, red, opacity = 0.3] (8,
5.8) to (8, 7.8);
\draw[-Triangle] (1.3, 2.4) to [out = 0, in = 270] (2, 3.35);
\draw[-Triangle] (5.9, 2.6) to [out = 180, in = 270] (4.3, 3.4);
\end{axis}
\end{tikzpicture}
\end{center}
What I did not tell you was that arrowheads can be appended to both the end of an
arrow and the start of an arrow. So the arrow with an arrowhead at its tail and head
takes the form of:
\draw[out arrowhead-in arrowhead] (A) to (B);
Dimension lines use the arrowhead “|”, which is a nice symbolic description of how
the arrow looks. We have:
\draw[|-|] (A) to (B);
The difference between QE and Q0 is the reduction of the quantity of gas con-
sumed after the imposition of the excise tax. To illustrate that on the graph, we will
draw a dimension indicator from the bottom of Q0 to QE . Below this, we will add a
label with the text “Consumption reduction.” Since Q0 is at Q = 4.14 and QE is at
Q = 5.05, we have:
\draw[|-|] (4.14, -1) to (5.05, -1);
\node [below] at (4.59, -1) {Consumption reduction};
51
done by adding the parameter align = left to tell how the stacked text should
align (either left, right, or center), and by adding two backslashes—“\\”—where we
want the line to break. Accordingly, the code for dimension lines and labels for the
consumer and producer incidences is:
\draw[|-|] (-1, 5.96) to (-1, 3.8);
\node [below, align = left] at (-2.3, 6) {Consumer \\ incidence};
\draw[|-|] (-1, 3.6) to (-1, 2.8);
\node [below, align = left] at (-2.3, 3.5) {Producer \\ incidence
};
Adding a dimension line from PS to P 0 representing the total tax and adding all
of the dimension lines and labels mentioned so far results in Figure 6-2.
Price, P
S0
E0
P0 S
Consumer
A
incidence
Tax
PE C E
Producer PS
B F
incidence
D
Gasoline, Q
0 Q0 QE
Consumption reduction
52
in the last subsection. While pgfplots has its own inbuilt legend feature, it is rather
unwieldy to use. Instead, we are going to use a text label and put it at the top-right
of the graph. The label should allow line breaks and have a black border drawn
around it. So we will use:
\node [below right, draw, align = left] at (10.5, 10) {
% Insert text here
};
Recall that adding the parameter align to the node command allows line break—
using \\—to be used within the label. Also, since the align is set to left, text lines
will be flushed to the left. These were covered in the previous subsection. What
is new, however, is the draw node parameter, which draws a black border around
the label. In the command, the top-left of the legend will be at (10.5, 10), which
corresponds to the top-right of the graph—where we want the legend to go. Adding
text that describes what the areas represent, we have:
\node [below right, draw, align = left] at (10.5, 10) {
$A$ + $C$ : Consumer surplus loss \\
$B$ + $F$ : Producer surplus loss \\
$A$ + $B$ : Total tax revenue \\
$C$ + $F$ : Deadweight loss
};
Using the above node command to add a legend to the graph, we get Figure 6-3.
53
Price, P
A + C : Consumer surplus loss
S0
B + F : Producer surplus loss
A + B : Total tax revenue
E0 C + F : Deadweight loss
0 S
P
Consumer
A
incidence
Tax
PE C E
Producer PS
B F
incidence
D
Gasoline, Q
0 Q0 QE
Consumption reduction
As it stands, the legend looks a bit boring. To improve the aesthetics of the
legend, we could add a colored background to the letters A, B, C, and F , to visually
connect it to the coloured areas which they point to. It would look good if A were
coloured a very transparent teal, B were coloured a very transparent violet, and so
on.
Fortunately, the xcolor package has a command to do exactly that. The xcolor
command to add a coloured background to text takes the form of:
\fcolorbox{frame colour}{background colour}{text}
In this command, the frame colour is the colour which surrounds the edges of the
coloured background. The background colour is the colour behind the text. For the
A text in the legend, since we want its background to be a very transparent teal, the
command we want is:
\fcolorbox{black}{teal!10}{$A$}
54
The above command produces: A . (As seen here, coloured text backgrounds can
be used within inline text as well.) Notice that the command does not end with a
semicolon, this is because it is not a TikZ command.
While the A looks fine, the widths of the background colour is determined by
the widths of the text within it. So we hit a snag when using multiple background
colours for texts with varying widths. For example, the background colour for M
is wider than the one for l . Beside each other, the inconsistent widths are notice-
able. To fix this, we will use the makebox LaTeX command (\makebox[width]
{text}) with the width of the height of “X”, (\fontcharht\font`X). Mean-
ing the command we will be using to make a coloured background for the letters
is:
\fcolorbox{black}{teal!10}{\makebox[\fontcharht\font`X]{$A$}
8
For example, adding a grave accent to “a” using \‘a produces “à”.
55
% Legend
\node [below right, draw, align = left] at (10.5, 10) {
\fcolorbox{black}{teal!10}{\makebox[\fontcharht\font`X]{$A$}} +
\fcolorbox{black}{teal!25}{\makebox[\fontcharht\font`X]{$C$}}
: Consumer surplus loss \\
\fcolorbox{black}{violet!10}{\makebox[\fontcharht\font`X]{$B$}} +
\fcolorbox{black}{violet!25}{\makebox[\fontcharht\font`X]
{$F$}} : Producer surplus loss \\
\fcolorbox{black}{teal!10}{\makebox[\fontcharht\font`X]{$A$}} +
\fcolorbox{black}{violet!10}{\makebox[\fontcharht\font`X]
{$B$}} : Total tax revenue \\
\fcolorbox{black}{teal!25}{\makebox[\fontcharht\font`X]{$C$}} +
\fcolorbox{black}{violet!25}{\makebox[\fontcharht\font`X]
{$F$}} : Deadweight loss
};
Price, P
A + C : Consumer surplus loss
S0
B + F : Producer surplus loss
A + B : Total tax revenue
E0 C + F : Deadweight loss
0 S
P
Consumer
A
incidence
Tax
PE C E
Producer PS
B F
incidence
D
Gasoline, Q
0 Q0 QE
Consumption reduction
Figure 6-4: The effect of a gasoline tax on consumption and production and total
tax revenue.
56
And viola! We have added dimension lines and a legend, further communicating
what different sections of the graph mean. Now, anyone looking at this graph would
pictorially understand that consumers bear the bulk of the tax incidence and the sur-
plus loss from a gasoline excise tax—and why. (Assuming that supply is relatively
price-elastic and demand is relatively price-inelastic.) The code that produces Fig-
ure 6-4 is:
\begin{center}
\hspace*{-3cm}\begin{tikzpicture}
\begin{axis}[
scale = 1.2,
xmin = 0, xmax = 10,
ymin = 0, ymax = 10,
axis lines* = left,
xtick = {0}, ytick = \empty,
clip = false,
]
% Colouring areas
\fill[teal, opacity = 0.1] (0, 3.53) -- (4.14, 3.53) -- (4.14,
5.96) -- (0, 5.96);
\fill[violet, opacity = 0.1] (0, 3.53) -- (4.14, 3.53) -- (4.14,
3) -- (0, 3);
\fill[teal, opacity = 0.25] (4.14, 3.53)-- (5.05, 3.53) -- (4.14,
5.96);
\fill[violet, opacity = 0.25] (4.14, 3)-- (5.05, 3.53) -- (4.14,
3.53);
% Dashed lines
\addplot[color = black, dashed, thick] coordinates {(0, 5.96)
(4.14, 5.96) (4.14, 0)};
\addplot[color = black, dashed, thick] coordinates {(0, 3.53)
(5.05, 3.53) (5.05, 0)};
57
\addplot[color = black, dashed, thick] coordinates {(0, 3) (4.1,
3)};
% Coordinate points
\addplot[color = black, mark = *, only marks, mark size = 3pt]
coordinates {(4.14, 5.96) (5.05, 3.53)};
% Labels
\node [right] at (current axis.right of origin){Gasoline, $Q$};
\node [above] at (current axis.above origin) {Price, $P$};
\node [above] at (5.25, 3.6) {$E$};
\node [above] at (4.35, 6.1) {$E^\prime$};
\node [right] at (6, 1) {$D$};
\node [right] at (9, 6) {$S$};
\node [right] at (9, 9) {$S^\prime$};
\node [left] at (0, 3.7) {$P_E$};
\node [left] at (0, 2.8) {$P_S$};
\node [left] at (0, 5.96) {$P^\prime$};
\node [below] at (5.05, 0) {$Q_E$};
\node [below] at (4.14, 0) {$Q^\prime$};
\node [above] at (2, 4.7) {$A$};
\node [above] at (1, 2) {$B$};
\node [above] at (4.5, 3.5) {$C$};
\node [above] at (6.2, 2.2) {$F$};
% Arrows
\draw[-{Triangle[length=4mm, width=2mm]}, red, opacity = 0.3] (8,
5.8) to (8, 7.8);
\draw[-Triangle] (1.3, 2.4) to [out = 0, in = 270] (2, 3.35);
\draw[-Triangle] (5.9, 2.6) to [out = 180, in = 270] (4.3, 3.4);
% Dimension lines
\draw[|-|] (4.14, -1) to (5.05, -1);
\node [below] at (4.59, -1) {Consumption reduction};
\draw[|-|] (-1, 5.96) to (-1, 3.8);
\node [below, align = left] at (-2.3, 6) {Consumer \\ incidence};
\draw[|-|] (-1, 3.6) to (-1, 2.8);
\node [below, align = left] at (-2.3, 3.5) {Producer \\ incidence
58
};
\draw[|-|] (-3.6, 5.96) to (-3.6, 2.8);
\node [below, align = left] at (-4.2, 4.7) {Tax};
% Legend
\node [below right, draw, align = left] at (10.5, 10) {
\fcolorbox{black}{teal!10}{\makebox[\fontcharht\font`X]{$A$}} +
\fcolorbox{black}{teal!25}{\makebox[\fontcharht\font`X]{$C$}}
: Consumer surplus loss \\
\fcolorbox{black}{violet!10}{\makebox[\fontcharht\font`X]{$B$}} +
\fcolorbox{black}{violet!25}{\makebox[\fontcharht\font`X]
{$F$}} : Producer surplus loss \\
\fcolorbox{black}{teal!10}{\makebox[\fontcharht\font`X]{$A$}} +
\fcolorbox{black}{violet!10}{\makebox[\fontcharht\font`X]
{$B$}} : Total tax revenue \\
\fcolorbox{black}{teal!25}{\makebox[\fontcharht\font`X]{$C$}} +
\fcolorbox{black}{violet!25}{\makebox[\fontcharht\font`X]
{$F$}} : Deadweight loss
};
\end{axis}
\end{tikzpicture}\hspace*{-3cm}
\end{center}
7 Conclusion
With this toolbox, you can create virtually any economic graph. The effort to learn
pgfplots and LaTeX is worth it. While on one hand, most word processors such
as Google Docs (with Google Sheets) and Word (with Excel) can provide the ne-
cessities of economic graphs—axes, lines, curves, and labels—pgfplots has more
flexibility, from shading areas, to adding dashed lines, and to adding dimension
lines. All done in style.
Of course, since it is LaTeX, this is only the tip of the iceburg. Everyone stands
on the shoulders of giants. First, Donald Knuth created TeX to typeset documents.
Then Leslie Lamport created LaTeX as a markup to TeX. Then Till Tantau created
TikZ on top of this foundation to create graphics. After, before, and between this
59
sequence is a list of many other contributors to the giant on which we stand. Finally,
we come along and, with serendipity, find out that we can create beautiful and sleek
graphs for economics.
Yet, we can always do more. For instance, we could automate the graph creation
by defining variables and automatically calculating the points of intersection. That,
however, is outside the scope of this guide.
If I have done my job successfully, you have partially scaled LaTeX’s reputable
learning curve in this one domain of making graphs. If I have not, you have been
left abandoned, with no guidance on how to begin your ascent (at least, not from
me!). Let us hope for the former.
8 Resources
Getting started with LaTeX and learning
• Overleaf: https://www.overleaf.com/.
If installing LaTeX is too much of a commitment, there are many online La-
TeX editors that are sufficient for this guide. Overleaf has pgfplots and xcolor
already installed, so you do not need to worry about that. On the subject of
pricing, they offer a free version which contains all the essentials and only
lacks a few specialized features such as GitHub integration or real-time col-
laboration.
60
subforum specifically deals with LaTeX, which includes pgfplots. Of course,
if you have a question, first use the search feature to check if it has been
answered before. Then, read the rules and ask away.
61
9 Other examples
Again, all of the finished graphs in this guide—the PDFs and the code—are avail-
able on the GitHub repository, including the examples below. The repository can
be accessed at https://github.com/jackypacky/pgf-econ-graphs.
Rent, P
PE E
E0
Pc Ceiling
D
Apartments, Q
0 Qs QE Qd
Apartments lost
Shortage
62
A : Producer surplus gain and consumer surplus loss
B + F : Deadweight loss
C : Tariff revenue
Price, P Price, P
S
PT PT S0
Tariff
A B C F C B+F
PW PW S
D D
Quantity, Q Imports, Q
0 QS Q0S Q0D QD 0 Q0 QE
Q0
QE
Figure 9-2: The effect of tariffs in a small economy on the domestic market (L)
and the import market (R).
Qy B
W0
A Qx
Figure 9-3: The market equilibrium, W 0 , in an Edgeworth box between two con-
sumers, A and B, and two commodities, x and y.
63