Documentos de Académico
Documentos de Profesional
Documentos de Cultura
1 Objectivos
2 Introducción
4 Histograma
5 Boxplot
6 Múltiples gráficas
7 Aumentando la Complejidad
Aspectos Técnicos
scipy
matplotlib
numpy
25
import numpy as np
import pylab as pl 20
pl.plot(x, y)
# show the plot on the screen 5
pl.show()
0
1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
25
import numpy as np
20
import pylab as pl
# Make an array of x values
x = [1, 2, 3, 4, 5] 15
pl.show()
0
1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
Indicador Color
b blue - azul
g green - verde
r reed - rojo
c cyan -
m magenta -
y yellow - amarillo
k black - negro
w white - blanco
Indicador Estilo
’-’ solid line style
’–’ dashed line style
’-.’ dash-dot line style
’:’ dotted line style
pl.plot(x, y, ’o’)
’.’ point marker
’s’ square marker
’p’ pentagon marker
’*’ star marker
http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.pl
import numpy as np
import pylab as pl
# Make an array of x values 30
Plot of y vs. x
x = [1, 2, 3, 4, 5]
# Make an array of y values for each x value 25
pl.plot(x, y)
# give plot a title
y axis
15
pl.title(’Plot of y vs. x’)
# make axis labels
10
pl.xlabel(’x axis’)
pl.ylabel(’y axis’)
# set axis limits 5
pl.xlim(0.0, 7.0)
pl.ylim(0.0, 30.) 0
0 1 2 3 4 5 6 7
x axis
# show the plot on the screen
pl.show()
import numpy as np
import pylab as pl
# Make x, y arrays for each graph
x1 = [1, 2, 3, 4, 5] 30
Plot of y vs. x
y axis
15
# give plot a title
pl.title(’Plot of y vs. x’)
10
# make axis labels
pl.xlabel(’x axis’)
pl.ylabel(’y axis’) 5
import numpy as np
import pylab as pl
# Make x, y arrays for each graph
x1 = [1, 2, 3, 4, 5]
y1 = [1, 4, 9, 16, 25] 30
Plot of y vs. x
green circles
y2 = [2, 4, 8, 12, 16] 25
y axis
15
pl.title(’Plot of y vs. x’)
# make axis labels
10
pl.xlabel(’x axis’)
pl.ylabel(’y axis’)
# set axis limits 5
pl.xlim(0.0, 9.0)
pl.ylim(0.0, 30.) 0
0 1 2 3 4 5 6 7 8 9
x axis
# make legend
pl.legend([plot1, plot2], (’red line’, ’green circles’), ’best’, numpoints=1)
# show the plot on the screen
pl.show()
250
import numpy as np
import pylab as pl
# make an array of random numbers with 200
#a gaussian distribution with
# mean = 5.0
150
# rms = 3.0
# number of points = 1000
data = np.random.normal(5.0, 3.0, 1000) 100
# make a histogram of the data array
pl.hist(data)
50
# make plot labels
pl.xlabel(’data’)
pl.show() 0
5 0 5 10 15 20
data
import numpy as np
300
import pylab as pl
# make an array of random numbers with
250
#a gaussian distribution with
# mean = 5.0
200
# rms = 3.0
# number of points = 1000
data = np.random.normal(5.0, 3.0, 1000) 150
pl.hist(data)
pl.hist(data, alpha=0.3)
x = mu + sigma * np.random.randn(10000)
# the histogram of the data
0.020
n, bins, patches = plt.hist(x, 50, normed=1, \
Probability
facecolor=’g’, alpha=0.75)
0.015
plt.xlabel(’Smarts’)
plt.ylabel(’Probability’)
0.010
plt.title(’Histogram of IQ’)
plt.text(60, .025, r’$\mu=100,\ \sigma=15$’)
plt.axis([40, 160, 0, 0.03]) 0.005
plt.grid(True)
plt.show() 0.00040 60 80 100 120 140 160
Smarts
20
import numpy as np
from pylab import * 15
#gaussian distributions
dataset_1 = np.random.normal(5.0, 3.0, 1000) 10
0
datos=[dataset_1, dataset_2, dataset_3]
xticks( arange(3), (’Dataset 1’, ’Dataset 2’, \
5
’Dataset 3’) )
10
boxplot(datos)
show() 15
Dataset 1 Dataset 2 Dataset 3
0.6
0.4
0.2
def f(t): 0.0
0.4
0.6
plt.figure(1) 0.5
plt.subplot(211)
plt.plot(t1, f(t1), ’bo’, t2, f(t2), ’k’) 0.0
plt.subplot(212) 0.5
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import NullFormatter
axScatter = plt.axes(rect_scatter)
axHistx = plt.axes(rect_histx)
axHisty = plt.axes(rect_histy)
# no labels
axHistx.xaxis.set_major_formatter(nullfmt)
axHisty.yaxis.set_major_formatter(nullfmt)
axHistx.set_xlim( axScatter.get_xlim() )
axHisty.set_ylim( axScatter.get_ylim() )
plt.show()
Gracias
¿Preguntas?
¿Más preguntas?