Skip to content

This repository shares TikZ coding which is able to create plots in LaTeX.

Notifications You must be signed in to change notification settings

IanHo2019/TikZ_Plotting

Repository files navigation

Using TikZ and PGF to Plot in LaTeX

This repository shares TikZ and PGF coding (written by Ian He and JaeSeok Oh) to create plots in LaTeX. To see the coding for any plot in the following sections, please click the figure. The hyperlink will lead you to our corresponding tex file.

Contact:

🥸 Ian: [email protected].

😎 JaeSeok: [email protected].

Comments are always welcomed!

Introduction

TikZ and PGF are languages commonly used in LaTeX for producing vector graphics, with lots of wonderful features including the drawing of points, lines, arrows, and shapes. More precisely, PGF is a lower-level language, while TikZ is a set of higher-level macros that use PGF.

To replicate the plots we create in the following sections, you must type the codes below in your LaTeX preamble.

\usepackage{graphicx, float, caption, subcaption, tzplot, asymptote, pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{calc, calligraphy, decorations.pathreplacing, fit, patterns, shadows, shapes.geometric, shapes.misc}

\usepackage{xcolor}
\definecolor{main}{RGB}{0,166,82}
\definecolor{second}{RGB}{32,178,170}

\usepackage{amsmath, amssymb, bbm, dutchcal}

Note:

  • The graphicx package (documentation) provides some useful optional arguments to the \includegraphics command.
  • The float package (documentation) improves the interface for defining floating objects, such as figures and tables. By default, we can use something [h] (here), t (top), and b (bottom) to determine the figure positioning; however, these positioning options are not strong --- LaTeX still has some flexibility to select the best position in its mind. To precisely fix the position of a floating objects, we have to use the parameter [H] from float.
  • The caption (documentation) and subcaption (documentation) packages allow us to customize the captions and subcaptions in floating environments like figure, table, subfigure, and subtable.
  • The tzplot package (documentation) provides some TikZ-based macros to make it easy to draw graphs. For example,
    • The \tzaxes command draws the x-axis and the y-axis quickly.
    • The \tzfn command plots a function over a specified domain.
    • The \tzbezier command draws a Bézier curve with one or two control points from the first coordinate to the last coordinate.
    • The \tzdot and \tzcdot commands add a label to a dot (with two optional patterns and two optional sizes).
  • The asymptote package (documentation) provides a lot of commands for 2D and 3D high-quality level technical drawing.
  • The pgfplots package (documentation) allows us to draw high-quality function plots. In particular, it supports axis scaling, axis ticks custimization, axis labels custimization, legend entries, etc. Note that pgfplots has been written with backwards compatibility; thus, new features occasionally lead to a different behavior. Therefore, we suggest to activate explicitly new features or bugfixes by writing \pgfplotsset{compat=1.18} in your preamble, where compat=1.18 is the highest compatibility level nowadays. The lowest level is compat=1.3.
  • asymptote and pgfplots provide basic functionalities and load the tikz and pgf packages (documentation) automatically. For special features, special libraries must be included. The libraries we use include
    • calc (making complex coordinate calculations);
    • calligraphy (enabling calligraphic style drawings);
    • decorations.pathreplacing (defining decorations that replace the to-be-decorated path by another path);
    • fit (defining options for fitting a node so that it contains a set of coordinates);
    • patterns (providing different patterns for filling in area);
    • shadows (helping add a partly transparent shadow to a path or node);
    • shapes.geometric (defining some shapes such as ellipses and polygons);
    • shapes.misc (defining additional shapes).
  • The xcolor package (documentation) allows us to select colors for hyper references, url links, plotting figures, etc. The basic color (e.g., blue and red) can be used directly by typing \color{color_name} to use it in the document. If additional colors are needed, we suggest to name the color first (for convenient future use) by the \definecolor{new_color_name}{RGB}{#,#,#} command, and then use the \color{new_color_name} command. The RGB model is our preferred model, but other models (e.g., rgb, HTML, HSB, etc.) are also available. There are some good websites to search for color codes:
    • For RGB model, see here.
    • For HTML model, see here.
  • The amsmath package (documentation) is a principal package for mathematical typesetting. Once amsmath is loaded, the packages amsbsy (for bold symbols), amsopn (for operator names) and amstext (for text embedded in mathematics) are also loaded.
  • The amssymb package provides an extended symbol collection, especially including some additional binary relation symbols (e.g., \boxdot, \boxplus, \boxtimes). Something noteworthy is that this package provides the \mathbb{ } command for producing blackboard bold characters.
  • The bbm package (documentation) provides blackboard variants of characters in math mode. The command is \mathbbm{ }, which produces the blackboard bold characters slighly different from those produced by \mathbb{ }.
  • The dutchcal package (documentation) reworks the mathematical calligraphic font ESSTIX13 in the package esstix (documentation) and adds a bold version.

Functions

Best Response Function

Best Response with a Continuum of NE

Cobb-Douglas Production Function

Dynamics of Solow Model

Engel Function

Engel Function

Indifference Curves from Different Utility Functions

Indifference Curve 1

Indifference Curve 2

Indifference Curve 3

Leontief Production Function

Leontief Production Function

Probability Distributions

Binomial Distribution $Binomial(n,p)$

Probability Mass Functions of Binomial(30, p)

Poisson Distribution $Pois(\lambda)$

Probability Mass Functions of Poisson Distributions

Normal Distribution $N(\mu, \sigma^2)$

Chi-Squared Distribution $\chi^2(n)$

F Distribution $F(n_1, n_2)$

Student t Distribution $t(n)$

Probability Density Functions of Student t Distributions

Gamma Distribution $\Gamma(\alpha, \beta)$

Probability Density Functions of Gamma Distributions

Shaded Areas

Venn Diagrams

Budget Set of a Consumer in a Two-Commodity Market

Budget Set

Input Requirement Set and Isoquant Curve

Input Requirement Set

Welfare Implication of a Monopolistic Market

Welfare Impication of Monopolistic Market

Game Trees

Matching Pennies

Entry Deterrence Game

Entry Deterrence Game Entry Deterrence Game with Imperfect Information

Predation Game

Predation Game

Bayesian Game

More Games

Models

Monopoly Market Model

Determining the Monopoly Output

Product Differentiation Model

Product Differentiation: Consumer Purchase Decisions Given Prices

Ramsey Growth Model (or Ramsey-Cass-Koopmans Model)

References

About

This repository shares TikZ coding which is able to create plots in LaTeX.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages