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.

152 lines
2.9 KiB

3 years ago
  1. \documentclass{article}
  2. \usepackage[utf8]{inputenc}
  3. \usepackage{tikz}
  4. \usepackage{pgfplots}
  5. %\usepackage{pgf-pie}
  6. \pgfplotsset{colormap/jet,width=3.5in,compat=1.16}
  7. \title{pgfplots}
  8. \author{Gerardo Marx Chávez-Campos}
  9. \date{February 2021}
  10. \begin{document}
  11. \maketitle
  12. \section{\LaTeX{} as calculator}
  13. This is an example to insert plots computed by \LaTeX{}:
  14. \begin{figure}[!htb]
  15. \centering
  16. \begin{tikzpicture}
  17. \begin{axis}
  18. \addplot{3*x+5};
  19. \addlegendentry{$f(x)$}
  20. \addplot{x^2+5};
  21. \addlegendentry{$g(x)$}
  22. \end{axis}
  23. \end{tikzpicture}
  24. \caption{Caption}
  25. \label{fig:my_label}
  26. \end{figure}
  27. \newpage
  28. \section{Bar plots}
  29. \begin{figure}[!htb]
  30. \centering
  31. \begin{tikzpicture}
  32. \begin{axis}[
  33. xlabel=Groups,
  34. ylabel= Counts,
  35. symbolic x coords={Group1, Group2, Group3},
  36. ybar,nodes near coords,
  37. enlarge x limits = 0.15,
  38. xtick=data
  39. ]
  40. \addplot coordinates{
  41. (Group1,3)
  42. (Group2,4)
  43. (Group3,2)
  44. };
  45. \addplot coordinates{
  46. (Group1,2)
  47. (Group2,4)
  48. (Group3,1)
  49. };
  50. \legend{MacOs, Windows}
  51. \end{axis}
  52. \end{tikzpicture}
  53. \caption{Caption}
  54. \label{fig:my_label}
  55. \end{figure}
  56. %\section{Pie charts}
  57. %\begin{figure}
  58. % \centering
  59. % \begin{tikzpicture}
  60. %\pie{22.97/Los Angeles Lakers,
  61. % 22.97/Boston Celtics,
  62. % 8.11/Golden State Warriors,
  63. % 8.11/Chicago Bulls,
  64. % 6.76/San Antonio Spurs,
  65. % 31.07/Other Teams}
  66. %\end{tikzpicture}
  67. % \caption{Caption}
  68. % \label{fig:my_label}
  69. %\end{figure}
  70. \section{Reading data from CSV files}
  71. \begin{tikzpicture}
  72. \begin{semilogyaxis}[
  73. legend pos=north west,
  74. %ylabel style={rotate =-90},
  75. xlabel=x,
  76. ylabel=y]
  77. \addplot[color=black, mark=*, line width=1pt] table[x=time, y=voltage, col sep=comma]{data.csv};
  78. \addlegendentry{voltage}
  79. \addplot table[x=time, y=current, col sep=comma]{data.csv};
  80. \addlegendentry{current}
  81. \end{semilogyaxis}
  82. \end{tikzpicture}
  83. \section{3D Plots}
  84. \begin{figure}[!htb]
  85. \centering
  86. \begin{tikzpicture}
  87. \begin{axis}
  88. \addplot3[
  89. mesh,
  90. samples=50,
  91. domain=-10:9
  92. ]
  93. {sin(deg(sqrt(x^2+y^2)))/sqrt(x^2+y^2)};
  94. \addlegendentry{$f(x)$}
  95. \end{axis}
  96. \end{tikzpicture}
  97. \caption{The Mexican hat}
  98. \label{fig:my_label}
  99. \end{figure}
  100. \section{How to configure PGFPlots}
  101. \begin{figure}[!h]
  102. \centering
  103. % \includegraphics{}
  104. \begin{tikzpicture}
  105. \begin{axis}[
  106. xlabel=time $t$,
  107. mark size =2.5pt,
  108. ylabel= $f(t)$
  109. legend pos=north west,
  110. ymajorgrids=true,
  111. grid style=dashed,
  112. ]
  113. \addplot[
  114. dashed,
  115. domain=-3:3,
  116. samples=20,
  117. mark=*,
  118. color=black,
  119. line width=1pt,
  120. ]
  121. {x^2+9};
  122. \addlegendentry{Eq1}
  123. \addplot[
  124. dotted,
  125. mark options={solid},
  126. domain=-3:3,
  127. samples=20,
  128. mark=o,
  129. line width=1pt,
  130. color=black!40!white]
  131. {20*sin(2*x*20)};
  132. \addlegendentry{$\sin(40x)$}
  133. \end{axis}
  134. \end{tikzpicture}
  135. \caption{Caption}
  136. \label{fig:my_label}
  137. \end{figure}
  138. \end{document}