nm9505

GRAFICOS EN TIKZ Y PGFPLOTS

Jan 12th, 2023 (edited)
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 8.27 KB | Science | 0 0
  1. \documentclass[11pt,a4paper]{article}
  2. \usepackage[a4paper,lmargin=2cm,rmargin=2cm,bottom=2cm,top=2cm]{geometry}
  3. \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{amsmath}
  4. \usepackage{amsfonts} \usepackage{amssymb} \usepackage{graphicx}
  5. \usepackage{color}
  6. \usepackage{color,colortbl}
  7. %Paquete para Referencias Web
  8. \usepackage{hyperref} [colorlinks=true,linkcolor=black,citecolor=black,filecolor=magenta,urlcolor=blue]
  9. %Paquete de estilo de Referencias
  10. \urlstyle{same}
  11. % Package for si units
  12. \usepackage{siunitx}
  13. % Packages for making pictures with LaTeX
  14. \usepackage{tikz} \usetikzlibrary{shapes,arrows,positioning,fit,backgrounds,calc}
  15. \usepackage{pgfplots} \pgfplotsset{compat=1.15}
  16. \usetikzlibrary{datavisualization.formats.functions}
  17. % Package to superimpose text on an image
  18. %\usepackage[percent]{overpic}
  19. \title{Gráficos en \LaTeX, utilizando\\ TIKZ \& PGFPLOTS}
  20. %
  21. \author{ {\small Nimrod Rodríguez}\\
  22. {\small {nimrodga@hotmail.com}} }
  23. \date{}
  24. \begin{document}
  25. \maketitle
  26. %
  27. \renewcommand
  28. \abstractname{Resumen}
  29. \begin{abstract}Las siguientes ilustraciones muestran el uso de los paquetes \texttt{tikz} y \texttt{pgfplots}, en combinación con la librería \texttt{datavisualization,} para crear en forma directa, desde Móvil o PC, gráficos bien delineados en dos y tres dimensiones, en cualquier documento \LaTeX. En cada gráfico se utiliza el entorno \texttt{figure} para agregar una numeración automática y una descripción con el comando \texttt{\textbackslash caption};  la leyenda se puede incluir y estilizar de diversas formas: En \texttt{\textbackslash datavisualization} es conveniente hacerlo en su configuración, en otros puede utilizarse el comando \texttt{\textbackslash addlegendentry}, y en la forma más ordinaria mediante un nodo coodenado con \texttt{\textbackslash draw node at (x,y) \{texto\}}. En este documento no se incluyen códigos parciales de las ilustraciones, pero en el \textcolor{red}{enlace} anterior puede acceder al código completo del presente documento, en el cual notará que el preámbulo incluye más de lo necesario, pero es porque ha servido como plantilla para otros documentos. Si desea ejecutar el código será conveniente una app online, como VerbTeX u Overleaf, porque si usa una instalación local como TeXMaker u otra, tendrá que verificar que estén instaladas todas las librerías del preámbulo.
  30. \end{abstract}
  31.  
  32. \section {\texttt{\textbackslash addplot}} Ilustración en el uso del comando \texttt{\textbackslash addplot} de \texttt{pgfplots} mediante  \texttt{tikzpicture}, para incluir en un solo gráfico con leyenda, dos o más funciones, como también marcas mediante pares coordenados, como contenido formal de texto en un documento \LaTeX.
  33. \begin{figure}
  34. \centering
  35. \caption{\color{blue}Cuatro funciones analíticas y un par coordenado.}
  36.  
  37. \vspace{.5cm}
  38. \begin{tikzpicture}[scale=0.7]
  39. \begin{axis}
  40. [domain=-2:2,
  41. samples=300, legend pos=outer north east, help lines]
  42. %\addplot [] {e^(-0.5*(x^2))};
  43. \addplot [blue,dashed] {2*x};
  44. \addplot [blue,dashed] {2^(-x)};
  45. \addplot [red] {sin(deg(pi*x))};
  46. \addplot [green!70! black] {cos(deg(pi*x))};
  47. \addplot [magenta, mark = *] coordinates {( 1, 1/2)};
  48. \legend {$y = 2x$,$y =
  49. 2^{-x}$,$y = \sin(\pi x)$,$y = \cos(\pi x)$,(1,$\frac{1}{2}$)}
  50. \end{axis}
  51. \end{tikzpicture}
  52. \label{fig:analytical}
  53. \end{figure}
  54. \pagebreak
  55.  
  56. \section {\texttt{\textbackslash addplot3}} Un ejemplo de superficies en 3D.
  57. \begin{figure}[!ht]
  58. \centering
  59. \caption{Gráfico mediante \texttt{mesh} 3D, el argumento $r$, es en radianes}
  60. \begin{tikzpicture} [scale=0.8]
  61. \begin{axis}
  62. [legend pos=outer north east]
  63. \addplot3[color=brown,mesh, samples=50, domain=-8:8]
  64. {sin(deg(sqrt(x^2+y^2)))/sqrt(x^2+y^2)};
  65. \addlegendentry{$\frac{sin(r)}{r},$\ \ \tiny{$r=\sqrt{x^2+y^2}$}}
  66. \addplot3[color=red, mesh] {sin(deg(3.1416/2))};
  67. \addlegendentry[right]{Plano\ $\textcolor{red}{z}=\lim_{r \to 0} \frac{\sin r}{r}=1$}
  68. \end{axis}
  69. \end{tikzpicture}
  70. \end{figure}
  71.  
  72. \section {\texttt{\underline{Scientific Axes}} de \texttt{\textbackslash datavisualization}} Las funciones trigonométricas primarias.\\
  73. \begin{figure}[!ht]
  74. \centering
  75. \caption {Las funciones \texttt{seno}, \texttt{\textcolor{red}{coseno}} y \texttt{\textcolor{blue}{tangente}}}
  76. \begin{tikzpicture}[baseline]
  77. \datavisualization [scientific axes=clean,
  78. y axis=grid,
  79. visualize as smooth line/.list={sin,cos,tan},
  80. style sheet=strong colors,
  81. style sheet=vary dashing,
  82. sin={label in legend={text=$\sin x$}},
  83. cos={label in legend={text=$\cos x$}},
  84. tan={label in legend={text=$\tan x$}},
  85. data/format=function ]
  86. data [set=sin] {
  87. var x : interval [-0.5*pi:4];
  88. func y = sin(\value x r);
  89. }
  90. data [set=cos] {
  91. var x : interval [-0.5*pi:4];
  92. func y = cos(\value x r);
  93. }
  94. data [set=tan] {
  95. var x : interval [-0.3*pi:.3*pi];
  96. func y = tan(\value x r);};
  97. \end{tikzpicture}
  98. \end{figure}
  99.  
  100. \section{\texttt{\underline{School Book Axes}} de \texttt{\textbackslash datavisualization}} Un gráfico ligero de tipo cuaderno.
  101. \begin{figure}[!ht]
  102. \centering
  103. \caption{Parábola con eje vertical}
  104. \begin{tikzpicture}[scale=0.8]
  105. \datavisualization
  106. [school book axes={unit=10},
  107. visualize as smooth line,
  108. clean ticks,
  109. x axis={label=$x$},
  110. y axis={label=$f(x)$}, color= blue]
  111. data [format=function] {
  112. var x : interval [-20:20];
  113. func y = \value x*\value x/10;};
  114. \fill [blue!15, rounded corners]
  115. (1.8,1.5) rectangle (4.2,2.5);
  116. \draw (3, 2) node  [color=magenta] {$f(x) =\frac{1}{10}x^2$};
  117. \end{tikzpicture}
  118. \end{figure}
  119. \pagebreak
  120. %Diagrama de flujo
  121. \section{\texttt{\textbackslash usetikzlibrary$[$shapes, arrows, positioning$]$}}
  122. A continuación una ilustración en el uso de \texttt{\textbackslash usetikzlibrary$[$shapes, arrows, positioning$]$}, para crear un diagrama de flujo, comunmente utilizado para representar gráficamente un algoritmo en el análisis de modelos. El diagrama, se construye en el entorno definido por \texttt{\textbackslash begin\{ tikzpicture\} } y \texttt{\textbackslash end\{tikzpicture\} }, utilizando la configuración de \texttt{\textbackslash begin\{ tikzpicture\} } para definir inicialmente los elementos del diagrama, tales como \texttt{block}, \texttt{decision}, \texttt{cloud}, etc., los cuales posteriormente son dispuestos en filas y columnas mediante el comando \texttt{\textbackslash matrix}, el cual también se configura. Finalmente, aunque no es necesario, se agrega un entorno
  123. \texttt{\textbackslash begin\{scope\} } y \texttt{\textbackslash end\{scope\} }, el cual también se puede configurar en su inicio, para luego en este entorno, crear  las trayectorias entre los nodos, las cuales conectarán los elementos del diagrama.
  124. \\
  125. \begin{figure}[!ht]
  126. \centering
  127. \caption {Control de Modelos Algorítmicos}
  128. \begin{tikzpicture}
  129. %configuración de tikzpicture
  130. [decision/.style={diamond, draw=blue, thick, fill=red,
  131. text width=4.5em,align=flush center,text=yellow,
  132. inner sep=1pt},
  133. block/.style ={rectangle, draw=blue, thick, fill=green!70! blue,
  134. text width=5em,align=center, rounded corners,
  135. minimum height=4em},
  136. line/.style ={draw, thick, -latex’,shorten >=2pt},
  137. cloud/.style ={draw=red, thick, ellipse,fill=blue,text=yellow,
  138. minimum height=2em}]
  139. %Definición matricial de los elementos del diagrama
  140. \matrix [column sep=5mm,row sep=7mm]
  141. {
  142. % row 1
  143. \node [cloud] (expert) {\textbf{Fenómeno o  Proceso}}; &
  144. \node [block] (init) {inicializar modelo Algoritmico}; &
  145. \node [cloud] (system) {\textbf{Teoría}}; \\
  146. % row 2
  147. & \node [block] (identify) {identificar modelo}; & \\
  148. % row 3
  149. \node [block] (update) {actualizar modelo}; &
  150. \node [block] (evaluate) {evaluar modelo}; & \\
  151. % row 4
  152. & \node [decision] (decide) {\textbf{mejor candidato}}; & \\
  153. % row 5
  154. & \node [block] (parar) {parar}; & \\
  155. };
  156. %Entorno de estilo
  157. \begin{scope}[every draw/.style=line, thick, color=magenta]
  158. %Trazo de flujos
  159. \draw [->] (init.south) to (identify);
  160. \draw [->] (identify) to (evaluate);
  161. \draw [->] (evaluate) to (decide);
  162. \draw [->](update) |- (identify);
  163. \draw [->] (decide) -| node [near start,above=2pt] {no} (update);
  164. \draw [->] (decide) to node [midway, right=2pt] {si} (parar);
  165. \draw [->,dashed] (expert) to (init);
  166. \draw [->,dashed] (system) to (init);
  167. \draw [<->] [dashed] (system) |- (evaluate);
  168. \draw [<->,dashed] (expert.north) .. controls+(up:10mm) and +(up:10mm).. (system.north);
  169. \end{scope}
  170. \end{tikzpicture}
  171. \end{figure}
  172.  
  173. \end{document}
  174.  
Add Comment
Please, Sign In to add comment