~~stoggle_buttons~~ ===== Instalación de todos los backends ===== [[https://matplotlib.org/faq/usage_faq.html#what-is-a-backend]] pip install tk PyQt5 # Estos funcionan con pip ===== Trucos ===== import matplotlib.pyplot as plt plt.ion() # Interactive mode ON plt.rc('text', usetex=True) # Latex rendering plt.minorticks_on() # Needs to be set before calling plot.grid() plt.grid(True, which='both') plt.tick_params(axis='both', which='major', labelsize=20) # Plot tick size plt.tight_layout() # If xlabel gets cut off plt.xlabel('$\\lambda \\mathrm{ (nm)}$') plt.xlabel('$\\lambda \\text{ (nm)}$') # PETA fuertemente plt.xlabel('$\\lambda $\\text{ (nm)}') # Probar plt.title(r'Entrop\'ia') # renders to Entropía plt.title(r"$Regresi\'on$") # Renders to Regresión # Linear regression slope, intercept, r, prob2, see = scipy.stats.linregress(x, y) mx = x.mean() sx2 = ((x-mx)**2).sum() sd_intercept = see * np.sqrt(1./len(x) + mx*mx/sx2) sd_slope = see * np.sqrt(1./sx2) === Cambiar el preámbulo de matplotlib === import matplotlib.pyplot as plt plt.rc('text', usetex=True) plt.rc('text.latex', preamble=r'\usepackage{amsmath} \usepackage{foo-name} `...') matplotlib.verbose.level = 'debug-annoying' === Estilos de plots === [[https://medium.com/analytics-vidhya/drastically-beautifying-visualizations-with-one-line-styling-plots-35a5712c4f54|estilos de plots]] plt.style.use('fivethirtyeight') plt.style.use('ggplot') === Setup mínimo de tex para matplotlib === apt-get install texlive-base texlive texlive-fonts* apt-get install dvipng ===== animaciones ===== from matplotlib.animation import FuncAnimation from matplotlib.animation import writers Writer = writers['ffmpeg'] Writer = writers['ffmpeg_file'] # Para exportar muchos frames y no comerse la ram duration = 120 # En segundos fps = t_gridnum/duration if t_gridnum/duration > 25.0 else 25.0 # Mínimo 25fps writer = Writer(fps=fps) ani = FuncAnimation(fig, animate, init_func=init, frames=np.arange(len(times)), repeat=False, cache_frame_data=False) # Importante el cache_frame_data para mayor velocidad con vídeos de muchos frames [[https://brushingupscience.com/2016/06/21/matplotlib-animations-the-easy-way/]]