\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{julenx} \pdfinfo{ /Title (python-matplotlib.pdf) /Creator (Cheatography) /Author (julenx) /Subject (Python matplotlib Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{18A326} \definecolor{LightBackground}{HTML}{F0F9F1} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Python matplotlib Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{julenx} via \textcolor{DarkBackground}{\uline{cheatography.com/168626/cs/35539/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}julenx \\ \uline{cheatography.com/julenx} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 19th November, 2022.\\ Updated 2nd December, 2022.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{1.92234 cm} x{1.19002 cm} x{1.46464 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Creación básica de matriz 2x2 de gráficos}} \tn % Row 0 \SetRowColor{LightBackground} fig, ax = plt.subplots(2, 2) & fig = \seqsplit{plt.figure()} & \seqsplit{plt.figure()} \#Opcional \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.3731 cm} x{1.64772 cm} x{1.55618 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Creación básica de gráficos}} \tn % Row 0 \SetRowColor{LightBackground} ax{[}0,0{]}.plot(y1) & \seqsplit{fig.add\_subplot(2}, 2, 1) & \seqsplit{plt.subplot(2}, 2, 1) \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} & plt.plot(y1) & plt.plot(y1) \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{ax{[}0,1{]}.hist(y2, bins = n)}} & {\bf{fig.add\_subplot(2, 2, 2)}} & {\bf{plt.subplot(2, 2, 2)}} \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} & {\bf{plt.hist(y2, bins = n)}} & {\bf{plt.hist(y2, bins = n)}} \tn % Row Count 11 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Import}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{import matplotlib.pyplot as plt} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{import matplotlib as mpl} \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.38896 cm} x{2.58804 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Parámetros de plt.plot()}} \tn % Row 0 \SetRowColor{LightBackground} \{\{width=50\}\} & fig, ax = plt.subplots() \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} & g = ax.plot(data) \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} linestyle = "-" / linestyle = "solid" & g{[}0{]}.set\_linestyle("-{}-") \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{linestyle = "-{}-" / linestyle = "dashed"} \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{linestyle = "-." / linestyle = "dashdot"} \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{linestyle = "." / linestyle = "dotted"} \tn % Row Count 8 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{linestyle = "None" / linestyle = ""} \tn % Row Count 9 (+ 1) % Row 7 \SetRowColor{white} linewidth = n & g{[}0{]}.set\_linewidth(n) \tn % Row Count 11 (+ 2) % Row 8 \SetRowColor{LightBackground} marker = "o" & g{[}0{]}.set\_marker("o") \tn % Row Count 13 (+ 2) % Row 9 \SetRowColor{white} markeredgewidth & ancho del borde del marcador \tn % Row Count 15 (+ 2) % Row 10 \SetRowColor{LightBackground} markeredgecolor & color del borde del marcador \tn % Row Count 17 (+ 2) % Row 11 \SetRowColor{white} markerfacecolor & color de fondo del marcador \tn % Row Count 19 (+ 2) % Row 12 \SetRowColor{LightBackground} markerfacecoloralt & color alternativo para el color de fondo del marcador \tn % Row Count 22 (+ 3) % Row 13 \SetRowColor{white} markersize = n & g{[}0{]}.set\_markersize(n) \tn % Row Count 24 (+ 2) % Row 14 \SetRowColor{LightBackground} color & Este parámetro controla el color de la gráfica y acepta gran cantidad de formatos distintos: \{\{nl\}\} Uno de los siguientes nombres: 'blue', 'orange', 'green', 'red', 'purple', 'brown', 'pink', 'gray', 'olive' o 'cyan' \{\{nl\}\} Uno de los siguientes caracteres representando colores: 'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w' (por ejemplo, "b" representa "blue", azul) \{\{nl\}\} Tuplas de tres o cuatro valores entre 0 y 1 representando colores en formato RGB o RGBA, por ejemplo: (0.1, 0.3, 0.2) \{\{nl\}\} Una cadena de texto representando un número hexadecimal correspondiente a un color en formato RGB o RGBA, por ejemplo \#A055CC, o \#99CC3377 \{\{nl\}\} Un color en formato X11/CSS4 \{\{nl\}\} Un nombre de color del xkcd color survey precedido por "xkcd:" (por ejemplo, "xkcd:burnt orange") Cualquier nombre de color web, por ejemplo "Tomato" o "CornflowerBlue" \tn % Row Count 67 (+ 43) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.38896 cm} x{2.58804 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Parámetros de plt.plot() (cont)}} \tn % Row 15 \SetRowColor{LightBackground} drawstyle = "steps" & g{[}0{]}.set\_drawstyle("steps") \tn % Row Count 3 (+ 3) % Row 16 \SetRowColor{white} ax.plot(y, "-.y*", markersize = 15) & En lugar de especificar el color de la gráfica, el marcador a usar y el estilo de línea mediante los parámetros color, marker y linestyle que hemos visto, podemos añadir tras los parámetros x e y (o solo y) el parámetro {[}fmt{]} con el mismo objetivo. Este parámetro es una cadena de texto en la que podemos incluir (en cualquier orden) un carácter que indique el color de la línea, otro que indique el marcador a usar y uno o dos más para indicar el estilo de la línea. No es necesario añadir los tres datos. \tn % Row Count 29 (+ 26) % Row 17 \SetRowColor{LightBackground} plt.plot(y1, "", y2) & Si se utiliza este parámetro {[}fmt{]} es posible mostrar dos o más gráficas en el mismo conjunto de ejes ejecutando la función plot una sola vez \tn % Row Count 37 (+ 8) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.38896 cm} x{2.58804 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Parámetros de plt.plot() (cont)}} \tn % Row 18 \SetRowColor{LightBackground} label = "name" & g1{[}0{]}.set\_label("name") \tn % Row Count 2 (+ 2) % Row 19 \SetRowColor{white} plt.legend() & Activamos leyenda \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Función legend}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{ax.plot(y1, label = "Ene")} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} ax.plot(y2, label = "Feb") & Creación básica de etiquetas \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} ax.legend() & Activar leyenda \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} ax.legend({[}"Enero", "Febrero"{]}) & Cambiar nombres mostrados de etiquetas \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} ax.legend({[}"Enero", "Febrero"{]}, loc = "lower right") & Mostrar leyenda en esquina inferior derecha. Funciona también con números. 0 es la posición más óptima y 10 es el centro. \tn % Row Count 13 (+ 7) % Row 5 \SetRowColor{white} loc = (0.2, 0.6)) & tupla con la posición x e y de la leyenda con respecto al ancho y alto del área de la gráfica \tn % Row Count 18 (+ 5) % Row 6 \SetRowColor{LightBackground} ncol = 2 & permite especificar el número de columnas en las que se van a mostrar las etiquetas en la leyenda. En este caso, si tenemos dos etiquetas, se mostrará una al lado de la otra. \tn % Row Count 27 (+ 9) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{fontsize} \tn % Row Count 28 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{shadow} \tn % Row Count 29 (+ 1) % Row 9 \SetRowColor{white} facecolor & color de fondo \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Función legend (cont)}} \tn % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{edgecolor} \tn % Row Count 1 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{title} \tn % Row Count 2 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{title\_fontsize} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Curvas de nivel}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{X = np.linspace(-1.2, 1.2, 100) \{\{nl\}\} Y = np.linspace(-1.2, 1.2, 100) \{\{nl\}\} X, Y = np.meshgrid(X, Y) \{\{nl\}\} Z = np.abs(0.4 {\bf{ 2 - (0.6 - (X }} 2 + Y {\bf{ 2) }} 0.5) {\bf{ 2) }} 0.5} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{fig = plt.figure(figsize = (12, 6)) \{\{nl\}\} ax = fig.gca(projection='3d') \{\{nl\}\} surface = ax.contour3D(X, Y, Z, cmap = "hot") \{\{nl\}\} fig.colorbar(surface) \{\{nl\}\} plt.show()} \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{levels = 20} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}escoger el número de niveles a mostrar} \tn % Row Count 10 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{zdir = "x"} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}modificar el eje de referencia} \tn % Row Count 12 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{cmap = "hot"} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Mapa de color} \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Gráficos de dispersión}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{fig = plt.figure(figsize = (12, 6))} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax = fig.gca(projection='3d')} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Alternativa 1} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{ax = \seqsplit{fig.add\_subplot(projection} = "3d")} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Alternativa 2} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{fig, ax = plt.subplots(subplot\_kw = \{"projection":"3d"\})} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Alternativa 3} \tn % Row Count 8 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{ax.scatter3D({[}0,1{]}, {[}3,4{]}, {[}0,0{]})} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Hacemos 2 puntos distintos} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{fig = plt.figure(figsize = (12, 6))} \tn % Row Count 11 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{ax = fig.gca(projection='3d')} \tn % Row Count 12 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{for n in range(3):} \tn % Row Count 13 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~x = np.random.normal(0, (n + 1) * 3, 100)} \tn % Row Count 14 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~y = np.random.normal(0, (n + 1) * 3, 100)} \tn % Row Count 15 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~z = np.random.normal(0, (n + 1) * 3, 100)} \tn % Row Count 16 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~scatter = ax.scatter3D(x, y, z, label = n)} \tn % Row Count 17 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.legend()} \tn % Row Count 18 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{plt.show()} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Ejemplo con etiquetas} \tn % Row Count 20 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Histograma}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{h = ax.hist(y, bins=n, range=(start, finish))} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Histograma con n bins, y mostrando solo los valores entre start y finish} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{v, l, g = h} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Un histograma contiene tres elementos, el primero es un array con los valores de las barras/bins (altura) \{\{nl\}\} el segundo es un array que contiene los límites de cada bin en el eje x y el tercero es una lista de objetos gráficos (rectángulos) que representan cada barra} \tn % Row Count 10 (+ 7) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{h{[}2{]}{[}5{]}.set\_facecolor("OrangeRed")} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Referenciamos el objeto gráfico de la quinta barra y cambiamos esa barra a naranja} \tn % Row Count 13 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{density = True} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Mostrar en el eje y la densidad de probabilidad de 0 a 1. Otra opción es False y el valor por defecto es None. v saldría con los valores normalizados al usar True} \tn % Row Count 18 (+ 5) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{cumulative = True} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}determina si el histograma es construido de forma que cada bin incluya sus valores y los anteriores} \tn % Row Count 22 (+ 4) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{cumulative = -1} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}el histograma se construye al revés} \tn % Row Count 24 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{orientation = "horizontal"} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Mostrar el histograma en posición horizontal en vez de vertical} \tn % Row Count 27 (+ 3) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{color} \tn % Row Count 28 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Mostrar valores justo encima de cada bin \newline \newline `fig, ax = plt.subplots(figsize = (10, 8))` \newline `v, m, g = ax.hist(y, bins = 20)` \newline `for i, rect in enumerate(g):` \newline `~~~~posx = rect.get\_x()` \newline `~~~~posy = rect.get\_height()` \newline `~~~~ax.text(posx + 0.03, posy + 30, int(v{[}i{]}), color='black', fontsize = 12)` \newline `plt.show()`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Funciones}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{ax{[}0,0{]}.set\_title("Title")}} & {\bf{plt.title("Title")}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{ax{[}0{]}.set\_xticks(range(0,n), minor = name\_list)}} & {\bf{plt.xticks(range(0,n), name\_list)}} \tn % Row Count 6 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Basic functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{ax.plot(list)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Crear de forma explícita una figura y un conjunto de ejes} \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Personalización de figuras estilo OO}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{fig.set\_size\_inches(width}, height)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}figsize} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{fig.set\_facecolor("color")}} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}facecolor} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{fig.set\_edgecolor("color)}} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}edgecolor} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{fig = plt.figure(linewidth = 6)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}linewidth (no tiene equivalente)} \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.59264 cm} x{3.38436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{plt.title(""), plt.xlabel("") y plt.ylabel("")}} \tn % Row 0 \SetRowColor{LightBackground} alpha & transparencia del texto \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{backgroundcolor} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{color} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{fontfamily} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{fontname} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{fontsize} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} fontstretch & ancho de la fuente \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} fontstyle & 'normal', 'italic', 'oblique' \tn % Row Count 9 (+ 2) % Row 8 \SetRowColor{LightBackground} fontvariant & 'normal', 'small-caps' \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} fontweight & 'ultralight', 'light', 'normal', 'regular', 'bold', etc. \tn % Row Count 13 (+ 3) % Row 10 \SetRowColor{LightBackground} \seqsplit{horizontalalignment} & 'center', 'right', 'left' \tn % Row Count 15 (+ 2) % Row 11 \SetRowColor{white} \seqsplit{verticalalignment} & 'center', 'top', 'bottom', 'baseline', 'center\_baseline' \tn % Row Count 18 (+ 3) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{linespacing} \tn % Row Count 19 (+ 1) % Row 13 \SetRowColor{white} rotation & ángulo de rotación del texto (en grados) \tn % Row Count 21 (+ 2) % Row 14 \SetRowColor{LightBackground} position & posición x e y del título. Toma (x,y) \tn % Row Count 23 (+ 2) % Row 15 \SetRowColor{white} x & posición x del texto \tn % Row Count 24 (+ 1) % Row 16 \SetRowColor{LightBackground} y & posición y del texto \tn % Row Count 25 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Los parámetros position, x e y toman normalmente valores entre 0 y 1, correspondiendo el 0 al extremo izquierdo del espacio ocupado por el conjunto de ejes y el 1 al extremo derecho (o a los extremos inferior y superior, si nos referimos a la y). Pueden tomar también valores negativos o superiores a 1, pero en este caso el texto se mostrará fuera de los límites de los ejes. \newline \newline Todas las variantes orientadas a objetos toman title.set\_..., o ax.set\_label("name", parameter) \{\{noshy\}\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Límites de los ejes}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.xlim(start, finish)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax.set\_xlim(start, finish)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{ax.get\_xlim} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}método para leer los límites del eje en ambos lados} \tn % Row Count 5 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{nos interesa mostrar solo la parte de la gráfica situada entre los valores start y finish} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{MultipleLocator (OO)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{from matplotlib.ticker import MultipleLocator} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Es otra forma de establecer las marcas principales y secundarias} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{ax.xaxis.set\_major\_locator(MultipleLocator(10))}} \tn % Row Count 4 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{ax.xaxis.set\_minor\_locator(MultipleLocator(1))}} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}queremos que una gráfica muestre en el eje x las marcas principales cada 10 puntos y las marcas secundarias cada punto. Las marcas principales tienen etiquetas y las secundarias no.} \tn % Row Count 9 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Grid}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{ax.grid()} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Muestra el grid} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{alpha} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}grado de transparencia} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{color} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}color de las líneas del grid} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{linestyle} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}estilo de las líneas ('-', '-{}-', '-.', ':', etc.)} \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{linewidth} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}ancho de las líneas} \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{b} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}booleano que indica si se muestran o no las líneas} \tn % Row Count 14 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{which} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}puede tomar los valores 'major', 'minor' o 'both', indicando si estamos configurando el grid correspondiente a las marcas principales, a las secundarias o a ambas (habiendo usado MultipleLocator antes)} \tn % Row Count 20 (+ 6) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{axis} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}puede tomar los valores 'both', 'x' o 'y', y que indica a qué eje vamos a aplicar la configuración} \tn % Row Count 24 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Gráficos estáticos vs. dinámicos}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\%matplotlib inline} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}provoca que las imágenes se muestren estáticas dentro del código (comportamiento por defecto en Jupyter)} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\%matplotlib notebook} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}provoca que las imágenes generadas sean interactivas (y se muestren también insertadas en el cuaderno jupyter)} \tn % Row Count 8 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Scatter plot}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{ax.scatter(x, y)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Scatter plot} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{pd.unique(data.species)} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{colors = \{ "setosa": "Crimson", "versicolor": "RoyalBlue", "virginica": "DarkSeaGreen" \}} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{species\_color = data.species.map(colors)} \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{ax.scatter(data.sepal\_length}, data.sepal\_width, color = list(species\_color))} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Ejemplo de cómo crearíamos un scatter plot con diferentes colores dependiendo de una tercera variable.} \tn % Row Count 11 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{mostrar tres etiquetas. s=dotsize \newline \newline fig, ax = plt.subplots() \newline for species in set(data.species): \newline ~~ax.scatter( \newline ~~~~~~data.sepal\_length{[}data.species == species{]}, \newline ~~~~~~data.sepal\_width{[}data.species == species{]}, \newline ~~~~~~s = 30, \newline ~~~~~c = colors{[}species{]}, \newline ~~~~~label = species \newline ~~) \newline plt.legend() \newline plt.show()} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Gráficos en 3D}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{from mpl\_toolkits.mplot3d import Axes3D} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{X = np.arange(-10, 10, 0.25) \{\{nl\}\} Y = np.arange(-10, 10, 0.25) \{\{nl\}\} X, Y = np.meshgrid(X, Y) \{\{nl\}\} Z = np.sin(np.sqrt(X{\bf{2 + Y}}2))} \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{fig = plt.figure(figsize = (12, 6)) \{\{nl\}\} ax = fig.gca(projection='3d') \{\{nl\}\} surface = ax.plot\_surface(X, Y, Z, cmap = "coolwarm") \{\{nl\}\} fig.colorbar(surface) \{\{nl\}\} plt.show()} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Ejemplo} \tn % Row Count 9 (+ 5) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{surface = ax.plot\_wireframe(X, Y, Z, rcount = 25, ccount = 25)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Wireframes, especificando el número de muestras de los datos a utilizar en cada dirección (opcional)} \tn % Row Count 14 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Gráficos de líneas con barras de error}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{fig, ax = plt.subplots()} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax.errorbar(x, y, yerr = 1)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.show()} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ecolor} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}define el color de las barras de error} \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{elinewidth} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}define el ancho de las barras de error} \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{capsize} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}define el ancho de los topes que limitan cada barra de error} \tn % Row Count 10 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{marker = "o"} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Marcar cada punto} \tn % Row Count 12 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{y\_error = y * 0.25 + 0.5} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Ejemplo de error con porcentajes} \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Gráficos circulares}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{sns.set()} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{fig, ax = plt.subplots()} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{g = ax.pie(data)} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{labels = list} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Lista de etiquetas para cada valor} \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{colors = list} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Lista de colores para cada valor} \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{shadow = True} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Añadir sombreado} \tn % Row Count 9 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{explode = (0.2, 0, 0, 0)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Un valor para cada etiqueta. Hace que salgan separadas del resto.} \tn % Row Count 12 (+ 3) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{labeldistance = 1.1} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Distancia del texto de las etiquetas respecto al gráfico} \tn % Row Count 15 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{autopct = '\%.1f\%\%'} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Mostrar porcentajes encima de los slices del gráfico} \tn % Row Count 18 (+ 3) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{pctdistance = 0.7} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Distancia de los porcentajes del centro} \tn % Row Count 20 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.show()} \tn % Row Count 21 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Personalización de figuras estilo MatLab}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{fig = plt.figure(figsize = {[}width, height{]})} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}especificar el tamaño de la figura en pulgadas} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{fig = plt.figure(facecolor = "color")} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}color del fondo de la figura} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{fig = plt.figure(edgecolor = "color", linewidth = n)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}damos color al borde de la figura (por defecto es de color blanco) y con el parámetro linewidth definimos el ancho de dicho borde (por defecto es 0)} \tn % Row Count 10 (+ 6) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{plt.suptitle('Title', fontsize=n)} \tn % Row Count 11 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{fig.suptitle('Title', fontsize=n)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Título y tamaño de letra de la figura, no de las gráficas que vayan dentro.} \tn % Row Count 14 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Poner una gráfica encima de otra}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{fig, ax = plt.subplots(2, 2, sharex = True, sharey = True)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}todos los ejes de los diferentes conjuntos de ejes compartirán las mismas propiedades} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{fig = plt.figure()} \tn % Row Count 5 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{ax1 = plt.axes()} \tn % Row Count 6 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax1.plot(y1)} \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{ax2 = plt.axes({[}0.0, 0.0, 0.5, 0.5{]})} \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax2.plot(y2, color = "red")} \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.show()} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Si hacemos esto, la gráfica roja saldrá encima de la otra.} \tn % Row Count 12 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Marcas de ejes}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.xticks(range(start, finish, intervals), xtick\_labels)} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{ax.set\_xticks(range(start}, finish, intervals), xtick\_labels)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Si intervals no se indica, va de 1 en 1. xtick\_labels (opcional) es una lista cuyos valores reemplazarán los números. si la lista de etiquetas es más larga que la lista de marcas, se ignoran las etiquetas extras. Y si es más corta, las marcas para las que no haya etiqueta se muestran sin ella.} \tn % Row Count 11 (+ 9) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{minor=True} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Si usamos este parámetro, se añaden las nuevas marcas que indiquemos sobre las marcas que había antes} \tn % Row Count 15 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{ax.set\_xticklabels(xtick\_labels)}} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Tambíén podemos indicar únicamente las etiquetas con esta función} \tn % Row Count 18 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Relación de aspecto}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{ax.set\_aspect("aspect")} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}"aspect" puede ser "auto" (por defecto), "equal" o un número. Un 2 hará que la distancia entre los puntos del eje x sea el doble que la de y} \tn % Row Count 5 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{relación de tamaño entre una unidad del eje x y una unidad del eje y} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Estilos}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.style.available} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Consultar estilos} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{plt.style.use(style)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Cambiar estilo} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.style.use("default")} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Estilo default que no aparece en la lista de estilos} \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{mpl.rcParams{[}"figure.dpi"{]} = 72} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}una vez que has usado otro estilo, aun volviendo al estilo "default" verás que los tamaños por defecto de las figuras ha aumentado. los puntos por pulgada (dpi) de las figuras, que por defecto toma el valor 72, pasa a valer 100 al activar el estilo "default". Esta es la solución.} \tn % Row Count 15 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Mapas de color}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{https://matplotlib.org/stable/tutorials/colors/colormaps.html}} \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Adición de otros elementos gráficos}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{ax.text(x, y, "text")} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}x e y son las coordenadas según los ejes usados. Admite los atributos de title.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{transform = ax.transAxes} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Parámetro que cambia el tipo de coordenadas. 0,0 será la esquina inferior izquierda y 1,1 será la esquina superior derecha de la gráfica en la que aparece el texto} \tn % Row Count 8 (+ 5) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{transform = fig.transFigure} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Parámetro que cambia el tipo de coordenadas. 0,0 será la esquina inferior izquierda y 1,1 será la esquina superior derecha de la figura} \tn % Row Count 12 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax.annotate("Máximo local", (x1, y1), (x2, y2), arrowprops = dict())} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Mostrar un texto en x2 y2 con una flecha que apunta a x1 y1. El objeto dict almacena las propiedades de la flecha y es necesario crearlo para que aparezca.} \tn % Row Count 18 (+ 6) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.axhline(n)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Añade una línea recta horizontal. n es la posición según el eje y usado en la gráfica. Admite los mismos parámetros que plot.} \tn % Row Count 22 (+ 4) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{plt.axvline(42);} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Añade una línea recta vertical. n es la posición según el eje x usado en la gráfica. Admite los mismos parámetros que plot.} \tn % Row Count 26 (+ 4) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{from matplotlib.lines import Line2D} \tn % Row Count 27 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{l = Line2D({[}x1, y1{]}, {[}x2, y2{]})} \tn % Row Count 28 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{ax.add\_line(l)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Añade una línea recta que va desde un punto a otro según el eje usado en el gráfico. Admite los mismos parámetros que plot} \tn % Row Count 32 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Adición de otros elementos gráficos (cont)}} \tn % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{from matplotlib.patches import Rectangle, Circle, Ellipse, Polygon} \tn % Row Count 2 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{rect = Rectangle((x, y), width, height)} \tn % Row Count 3 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax.add\_patch(rect)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Crear un rectángulo. tupla con las coordenadas x e y de la esquina inferior izquierda, la anchura y la altura del rectángulo.} \tn % Row Count 7 (+ 4) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{circ = Circle((x, y), width, height)} \tn % Row Count 8 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax.add\_patch(circ)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Crear círculo/elipse. El ancho y alto son el radio.} \tn % Row Count 11 (+ 3) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{polygon = Polygon({[}{[}x1, y1{]}, {[}x2, y2{]}, {[}x3, y3{]}{]})} \tn % Row Count 12 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax.add\_patch(polygon)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Crear polígono. En el ejemplo se crear un triángulo donde las tres tuplas son la posición de los tres vértices.} \tn % Row Count 16 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{2D Histogram}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.style.use("default")} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{plt.hist2d(x, y)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{bins = (x,y)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}If int, the number of bins for the two dimensions (nx=ny=bins). - If `{[}int, int{]}`, the number of bins in each dimension (nx, ny = bins).} \tn % Row Count 7 (+ 5) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{plt.colorbar()} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Añadir barra de colores} \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Gráficos de barras}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{fig, ax = plt.subplots()} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax.bar(x, y)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.show()} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}y es la altura de cada barra} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax.bar(x, y1, label = "Producto A")} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{ax.bar(x, y2, bottom = y1, label = "Producto B")} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax.bar(x, y3, bottom = y1 + y2, label = "Producto C")} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Con el parámetro bottom se especifica que una barra se pondrá encima de la otra. Si no se especifica, saldrá una cubriendo a la otra.} \tn % Row Count 11 (+ 5) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{width = 0.3} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Cambia el ancho de las barras} \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax.barh(y, x)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Gráfico de barras horizontales} \tn % Row Count 15 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{ax.barh(y, x1, label = "Producto A")} \tn % Row Count 16 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax.barh(y, x2, left = x1, label = "Producto B")} \tn % Row Count 17 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{ax.barh(y, x3, left = x1 + x2, label = "Producto C")} \tn % Row Count 19 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax.legend(loc = (1.1, 0.8))} \tn % Row Count 20 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.show()} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Apilar barras en gráfico horizontal} \tn % Row Count 22 (+ 2) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ax.barh(y, x, height = 1)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Cambiar ancho de barras en gráfico horizontal} \tn % Row Count 24 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Boxplot}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.boxplot(data, labels = tips.day.unique())} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Violinplot}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.violinplot(data)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{bw\_method=1} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{sns.kdeplot(data)} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Curvas de nivel}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.style.use("default")} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{mpl.rcParams{[}"figure.dpi"{]} = 72} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def f(x, y): \{\{nl\}\} ~ return np.sin(x) {\emph{* 2 + np.cos(5 + x }} y) + 2 * np.cos(x)} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{x = np.linspace(0, 5, 100)} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{y = np.linspace(0, 5, 100)} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{X, Y = np.meshgrid(x, y)} \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.contour(X, Y, Z)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Curvas de nivel sin rellenar} \tn % Row Count 9 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{plt.contourf(X, Y, Z)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Curvas de nivel rellenas} \tn % Row Count 11 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{plt.colorbar()} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Mostrar barra de colores} \tn % Row Count 13 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{plt.show()} \tn % Row Count 14 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{levels = 15} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}determina el número de curvas a mostrar} \tn % Row Count 16 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{cmap = "coolwarm"} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}mapa de color a usar} \tn % Row Count 18 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{alpha} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}grado de transparencia} \tn % Row Count 20 (+ 2) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{linewidths = 4} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}ancho de los contornos} \tn % Row Count 22 (+ 2) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{linestyles = "dotted"} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}estilo: solid, dashed, dashdot o dotted} \tn % Row Count 24 (+ 2) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{fig, ax = plt.subplots() \{\{nl\}\} g = ax.contourf(X, Y, Z, levels = 15) \{\{nl\}\} fig.colorbar(g) \{\{nl\}\} plt.show()} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Ejemplo con fig y ax} \tn % Row Count 28 (+ 4) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{fraction = 0.20} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Porcentaje de la figura que se dedicará a la barra de color} \tn % Row Count 31 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Curvas de nivel (cont)}} \tn % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{aspect = 3.7} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Proporción alto-ancho de la barra de colores} \tn % Row Count 2 (+ 2) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{orientation = "horizontal"} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Cambiar orientación barra de colores} \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}