Repository for the international webinar 2021, prepared with Jade, ITM, and Óbuda universities.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
2.9 KiB

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
%\usepackage{pgf-pie}
\pgfplotsset{colormap/jet,width=3.5in,compat=1.16}
\title{pgfplots}
\author{Gerardo Marx Chávez-Campos}
\date{February 2021}
\begin{document}
\maketitle
\section{\LaTeX{} as calculator}
This is an example to insert plots computed by \LaTeX{}:
\begin{figure}[!htb]
\centering
\begin{tikzpicture}
\begin{axis}
\addplot{3*x+5};
\addlegendentry{$f(x)$}
\addplot{x^2+5};
\addlegendentry{$g(x)$}
\end{axis}
\end{tikzpicture}
\caption{Caption}
\label{fig:my_label}
\end{figure}
\newpage
\section{Bar plots}
\begin{figure}[!htb]
\centering
\begin{tikzpicture}
\begin{axis}[
xlabel=Groups,
ylabel= Counts,
symbolic x coords={Group1, Group2, Group3},
ybar,nodes near coords,
enlarge x limits = 0.15,
xtick=data
]
\addplot coordinates{
(Group1,3)
(Group2,4)
(Group3,2)
};
\addplot coordinates{
(Group1,2)
(Group2,4)
(Group3,1)
};
\legend{MacOs, Windows}
\end{axis}
\end{tikzpicture}
\caption{Caption}
\label{fig:my_label}
\end{figure}
%\section{Pie charts}
%\begin{figure}
% \centering
% \begin{tikzpicture}
%\pie{22.97/Los Angeles Lakers,
% 22.97/Boston Celtics,
% 8.11/Golden State Warriors,
% 8.11/Chicago Bulls,
% 6.76/San Antonio Spurs,
% 31.07/Other Teams}
%\end{tikzpicture}
% \caption{Caption}
% \label{fig:my_label}
%\end{figure}
\section{Reading data from CSV files}
\begin{tikzpicture}
\begin{semilogyaxis}[
legend pos=north west,
%ylabel style={rotate =-90},
xlabel=x,
ylabel=y]
\addplot[color=black, mark=*, line width=1pt] table[x=time, y=voltage, col sep=comma]{data.csv};
\addlegendentry{voltage}
\addplot table[x=time, y=current, col sep=comma]{data.csv};
\addlegendentry{current}
\end{semilogyaxis}
\end{tikzpicture}
\section{3D Plots}
\begin{figure}[!htb]
\centering
\begin{tikzpicture}
\begin{axis}
\addplot3[
mesh,
samples=50,
domain=-10:9
]
{sin(deg(sqrt(x^2+y^2)))/sqrt(x^2+y^2)};
\addlegendentry{$f(x)$}
\end{axis}
\end{tikzpicture}
\caption{The Mexican hat}
\label{fig:my_label}
\end{figure}
\section{How to configure PGFPlots}
\begin{figure}[!h]
\centering
% \includegraphics{}
\begin{tikzpicture}
\begin{axis}[
xlabel=time $t$,
mark size =2.5pt,
ylabel= $f(t)$
legend pos=north west,
ymajorgrids=true,
grid style=dashed,
]
\addplot[
dashed,
domain=-3:3,
samples=20,
mark=*,
color=black,
line width=1pt,
]
{x^2+9};
\addlegendentry{Eq1}
\addplot[
dotted,
mark options={solid},
domain=-3:3,
samples=20,
mark=o,
line width=1pt,
color=black!40!white]
{20*sin(2*x*20)};
\addlegendentry{$\sin(40x)$}
\end{axis}
\end{tikzpicture}
\caption{Caption}
\label{fig:my_label}
\end{figure}
\end{document}