Tutorial de Pyplot - Documentación de Matplotlib 3.1.0
Tutorial de Pyplot - Documentación de Matplotlib 3.1.0
Versión 3.1.0
Bifurcame en GitHub
https://matplotlib.org/3.1.0/tutorials/introductory/pyplot.html 1/14
21/10/2020 Tutorial de Pyplot - documentación de Matplotlib 3.1.0
https://matplotlib.org/3.1.0/tutorials/introductory/pyplot.html 2/14
21/10/2020 Tutorial de Pyplot - documentación de Matplotlib 3.1.0
import numpy as np
https://matplotlib.org/3.1.0/tutorials/introductory/pyplot.html 3/14
21/10/2020 Tutorial de Pyplot - documentación de Matplotlib 3.1.0
https://matplotlib.org/3.1.0/tutorials/introductory/pyplot.html 4/14
21/10/2020 Tutorial de Pyplot - documentación de Matplotlib 3.1.0
plt.figure(figsize=(9, 3))
plt.subplot(131)
plt.bar(names, values)
plt.subplot(132)
plt.scatter(names, values)
plt.subplot(133)
plt.plot(names, values)
plt.suptitle('Categorical Plotting')
plt.show()
https://matplotlib.org/3.1.0/tutorials/introductory/pyplot.html 5/14
21/10/2020 Tutorial de Pyplot - documentación de Matplotlib 3.1.0
plt.plot(x, y, linewidth=2.0)
https://matplotlib.org/3.1.0/tutorials/introductory/pyplot.html 6/14
21/10/2020 Tutorial de Pyplot - documentación de Matplotlib 3.1.0
In [70]: plt.setp(lines)
alpha: float
animated: [True | False]
antialiased or aa: [True | False]
...snip
def f(t):
return np.exp(-t) * np.cos(2*np.pi*t)
plt.figure()
plt.subplot(211)
plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k')
plt.subplot(212)
plt.plot(t2, np.cos(2*np.pi*t2), 'r--')
plt.show()
Puede borrar la cifra actual con clf() y los ejes actuales con cla(). Si le
resulta molesto que los estados (específicamente la imagen, la figura y
los ejes actuales) se mantengan detrás de escena, no se desespere: esto
es solo una envoltura delgada de estado alrededor de una API orientada
a objetos, que puede usar en su lugar ( ver tutorial del artista )
Si está haciendo muchas figuras, debe tener en cuenta una cosa más: la
memoria requerida para una figura no se libera por completo hasta que la
figura se cierra explícitamente con close(). Eliminar todas las
referencias a la figura y / o usar el administrador de ventanas para
eliminar la ventana en la que aparece la figura en la pantalla no es
suficiente, porque pyplot mantiene las referencias internas hasta que
close() se llama.
https://matplotlib.org/3.1.0/tutorials/introductory/pyplot.html 9/14
21/10/2020 Tutorial de Pyplot - documentación de Matplotlib 3.1.0
plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title('Histogram of IQ')
plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
plt.axis([40, 160, 0, 0.03])
plt.grid(True)
plt.show()
plt.title(r'$\sigma_i=15$')
https://matplotlib.org/3.1.0/tutorials/introductory/pyplot.html 10/14
21/10/2020 Tutorial de Pyplot - documentación de Matplotlib 3.1.0
Anotar texto
Los usos del text()comando básico anterior colocan el texto en una
posición arbitraria en los ejes. Un uso común del texto es anotar alguna
característica del gráfico, y el annotate()método proporciona una
funcionalidad auxiliar para facilitar las anotaciones. En una anotación,
hay dos puntos a considerar: la ubicación que se anota representada por
el argumento xyy la ubicación del texto xytext. Ambos argumentos son
(x,y)tuplas.
ax = plt.subplot(111)
plt.ylim(-2, 2)
plt.show()
https://matplotlib.org/3.1.0/tutorials/introductory/pyplot.html 11/14
21/10/2020 Tutorial de Pyplot - documentación de Matplotlib 3.1.0
plt.xscale ('registro')
# linear
https://matplotlib.org/3.1.0/tutorials/introductory/pyplot.html 12/14
21/10/2020 Tutorial de Pyplot - documentación de Matplotlib 3.1.0
plt.subplot(221)
plt.plot(x, y)
plt.yscale('linear')
plt.title('linear')
plt.grid(True)
# log
plt.subplot(222)
plt.plot(x, y)
plt.yscale('log')
plt.title('log')
plt.grid(True)
# symmetric log
plt.subplot(223)
plt.plot(x, y - y.mean())
plt.yscale('symlog', linthreshy=0.01)
plt.title('symlog')
plt.grid(True)
# logit
plt.subplot(224)
plt.plot(x, y)
plt.yscale('logit')
plt.title('logit')
plt.grid(True)
# Format the minor tick labels of the y-axis into empty st
# `NullFormatter`, to avoid cumbering the axis with too ma
plt.gca().yaxis.set_minor_formatter(NullFormatter())
# Adjust the subplot layout, because the logit one may tak
# than usual, due to y-tick labels like "1 - 10^{-3}"
plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, righ
wspace=0.35)
plt.show()
https://matplotlib.org/3.1.0/tutorials/introductory/pyplot.html 13/14
21/10/2020 Tutorial de Pyplot - documentación de Matplotlib 3.1.0
© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom y el equipo de desarrollo de Matplotlib; 2012 - 2018 El equipo
de desarrollo de Matplotlib.
Última actualización el 18 de mayo de 2019. Creado con Sphinx 1.8.5. Doc versión v3.1.0-4-g0078324e4.
https://matplotlib.org/3.1.0/tutorials/introductory/pyplot.html 14/14