\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
% Package for si units
\usepackage{siunitx}
% Packages for making pictures with LaTeX
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,fit,backgrounds,calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
% Package to superimpose text on an image
\usepackage[percent]{overpic}
\begin{document}
%
\title{\LaTeX \,\,Figures using\\ TIKZPICTURE, PGFPLOTS \& OVERPIC}
%
\author{
{\small Andreas Almqvist}$^{a,\ast}\text{\small}$\\
{$^{a}${\small Machine Elements, Lule\aa \ University of Technology, 97187, Lule\aa , Sweden}}\\
{$^{\ast}${\small Corresponding author's e-mail address: andreas.almqvist@ltu.se}}
}
\date{}
\maketitle
%
\begin{abstract}
Some examples of how the packages \texttt{tikz}, \texttt{pgfplots} can be used to create fully vectorized graphics directly in the latex document. An example of how a flow chart can be generated in latex is also given. It combines the packages \texttt{tikz} and \texttt{overpic} and shows how to overlay/embed intrinsic latex text onto images created elsewhere.
\end{abstract}
%
%
\vspace{0.5cm}\noindent
%
%
%
Figure~\ref{fig:analytical}, is the first example illustrating how to graph analytical functions with \texttt{tikzpicture} directly in latex. and how to colourise and label them.
%
\begin{figure}[!ht]
\centering
\begin{tikzpicture}
\begin{axis}
[
legend pos= north east,
axis lines = center,
domain=-1:2,
xlabel=$x$,
xmin=-1.5,
xmax=3,
xtick={-1,-1,0,1,2},
ylabel=$y$,
ymin=-1.5,
ymax=4,
ytick={-1,0,1,2,3},
samples=50,
]
\addplot [] {x/2};
\addplot [blue,dashed] {2^(-x)};
\addplot [red] {sin(deg(pi*x))};
\addplot [blue, mark = o] coordinates {( 1, 1/2)};
\legend{$x/2$,$2^{-x}$,$\sin(\pi x)$}
\end{axis}
\end{tikzpicture}
\caption{Graphs of three analytical functions.}
\label{fig:analytical}
\end{figure}
%
The second example is illustrated by Fig.~\ref{fig:xf1f2}, which depicts data from the plain-text file \texttt{xf1f2.txt} located in the subfolder \texttt{Data}. The data file has $3$ columns containing in its $1$\textsuperscript{st} column a list of $x$-values and values for the data $y=f_1(x)$ and $f_2(x)$, listed in column $2$ and $3$, respectively.
%
\begin{figure}[!ht]
\centering
\begin{tikzpicture}
\begin{axis}[
xlabel={$x$ (\SI{}{\metre})},
xmin=2,
xmax=256,
xmode=log,
log basis x={2},
ylabel={label (unit)},
ymin=0.4,
ymax=1,
enlargelimits=false,
legend pos=north east
]
\addplot[blue,mark=o] table[x index=0,y index=1] {Data/xf1f2.txt};
\addplot[red,mark=o,only marks] table[x index=0,y index=2] {Data/xf1f2.txt};
\legend{$f_1$,$f_2$}
\end{axis}
\end{tikzpicture}
\caption{Graphs of the data in the text file \texttt{xf1f2.txt} for the two functions $y=f_1$ and $f_2$.}
\label{fig:xf1f2}
\end{figure}
%
The second example is a flowchart including images inserted using the package \texttt{overpic}. It illustrates a solution procedure which can be applied to estimate the wear depth according to \eqref{eq:wear_depth_plastic}, i.e.,
%
\begin{equation}\label{eq:wear_depth_plastic}
{\Delta h}_{ij} = k\Delta sp_{ij} + {u_p}_{ij}.
\end{equation}
%
%
\begin{figure}
\centering
\begin{tikzpicture}[
node distance = 3mm and 9mm,
block/.style = {rectangle, draw, rounded corners,
text width =8em},
blockfig/.style = {text width =10em},
cloud/.style = {draw, ellipse, aspect=1.2}
]
% Place nodes
\node [blockfig] (twosurfini)
{\begin{overpic}[width=1\textwidth]{Figures/two_surfs_ini.pdf}
\put (10,33) {$ h_u$}
\put (10,9) {$ h_l$}
\end{overpic}};
\node [block, left= of twosurfini.west] (init) {Initial surface topographies and relative position};
\node [blockfig, below=of twosurfini.south] (twosurfcontact)
{\begin{overpic}[width=1\textwidth]{Figures/two_surfs_contact.pdf}
\put (25,33) {$ p$}
\end{overpic}};
\node [block, left= of twosurfcontact.west] (cm) {Run enhanced CM solver to compute $p$ \& $u_p$};
\node [blockfig, below=of twosurfcontact.south] (twosurfwear)
{\begin{overpic}[width=1\textwidth]{Figures/two_surfs_wear.pdf}
\put (32,19) {$ \Delta h + u_p$}
\end{overpic}};
\node [block, left= of twosurfwear.west] (wear) {Compute wear depth using \eqref{eq:wear_depth_plastic}};
\node [blockfig, below=of twosurfwear.south] (twosurfworn)
{\begin{overpic}[width=1\textwidth]{Figures/two_surfs_worn.pdf}
\put (23,23) {$h_l - (\Delta h + u_p)$}
\end{overpic}};
\node [block, left= of twosurfworn.west] (worn) {Remove material from the softer surface};
\node [blockfig, below=of twosurfworn.south] (twosurfshift)
{\begin{overpic}[width=1\textwidth]{Figures/two_surfs_shift.pdf}
\put (45,25) {$\Delta s$}
\end{overpic}};
\node [block, left= of twosurfshift.west] (shift) {Update relative position by $\Delta s$};
% Draw connections
\draw[-latex'] (init.south) -- (cm.north);
\draw[-latex'] (cm.south) -- (wear.north);
\draw[-latex'] (wear.south) -- (worn.north);
\draw[-latex'] (worn.south) -- (shift.north);
\node [coordinate, left = 1cm of shift] (shiftcr) {}; %% Coordinate on the right of shift
\node [coordinate, left = 1cm of cm] (cmcr) {}; %% Coordinate on the right of cm
\draw[-] (shift.west) -- (shiftcr);
\draw[-] (shiftcr) -- (cmcr);
\draw[-latex'] (cmcr) -- (cm.west);
\end{tikzpicture}
\caption{\small Flow chart of the solution procedure used for wear prediction. It shows how to combine \texttt{tikz} and \texttt{overpic} to overlay/embed intrinsic latex text onto images created elsewhere}
\label{fig:flowchartwear}
\end{figure}
%
\end{document}