Matplotlib - Pyplot PLT Numpy NP Scipy Seaborn Sns Scipy Random

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

12/8/2020 fdp

In [34]:

# importando modulos necesarios


%matplotlib inline

import matplotlib.pyplot as plt


import numpy as np
from scipy import stats
import seaborn as sns
from scipy import integrate
import random

# parametros esteticos de seaborn


sns.set_palette("deep", desat=.6)
sns.set_context(rc={"figure.figsize": (8, 4)})

In [35]:

x = lambda x: 1/4
integrate.quad(x, 0,1)

Out[35]:

$\displaystyle \left( 0.25, \ 2.7755575615628914e-15\right)$

In [46]:

for x in range(15):
print(random.uniform(0, 0.25))

0.08210634830982019
0.01804553854064045
0.06887849246580485
0.13356607860039327
0.14402898390329846
0.08080631190522783
0.11749251996164534
0.012240590850831512
0.15369388712377402
0.1261672056493299
0.02864313865139126
0.0706543863188922
0.23933535034215503
0.06931822847914099
0.09347972547918898

localhost:8890/lab 1/4
12/8/2020 fdp

In [47]:

# Graficando FMP
n, p = 30, 0.4 # parametros de forma de la distribución binomial
n_1, p_1 = 20, 0.3 # parametros de forma de la distribución binomial
x = np.arange(stats.binom.ppf(0.00, n, p),
stats.binom.ppf(0.1, n, p))
x_1 = np.arange(stats.binom.ppf(0.00, n_1, p_1),
stats.binom.ppf(0.1, n_1, p_1))
fmp = stats.binom.pmf(x, n, p) # Función de Masa de Probabilidad
fmp_1 = stats.binom.pmf(x_1, n_1, p_1) # Función de Masa de Probabilidad
plt.plot(x, fmp, '--')
plt.plot(x_1, fmp_1)
plt.vlines(x, 0, fmp, colors='b', lw=5, alpha=0.5)
plt.vlines(x_1, 0, fmp_1, colors='g', lw=5, alpha=0.5)
plt.title('Función de Masa de Probabilidad')
plt.ylabel('probabilidad')
plt.xlabel('valores')
plt.show()

localhost:8890/lab 2/4
12/8/2020 fdp

In [48]:

# Graficando Función de Densidad de Probibilidad con Python


FDP_normal = stats.norm(0, 1).pdf(x_1) # FDP
plt.plot(x_1, FDP_normal, label='FDP nomal')
plt.title('Función de Densidad de Probabilidad')
plt.ylabel('probabilidad')
plt.xlabel('valores')
plt.show()

In [49]:

x1 = lambda x: 3/4
integrate.quad(x1, 1, 2)

Out[49]:

$\displaystyle \left( 0.75, \ 8.326672684688674e-15\right)$

localhost:8890/lab 3/4
12/8/2020 fdp

In [51]:

for x in range(15):
print(random.uniform(0, 0.75))

0.15575038409728198
0.11336186072599086
0.016801282980445698
0.43512946073221637
0.5021044224880696
0.062444696666910604
0.24205310237637162
0.13686344439247672
0.294134766036973
0.43133907892433115
0.2536271045745959
0.246638043852114
0.3172061472122544
0.6350292805426465
0.5543380075204749

In [22]:

from sympy import integrate, init_printing


from sympy.abc import x
init_printing(use_latex="mathjax")
integrate(1/4, (x,0,1))

Out[22]:

$\displaystyle 0.25$

In [55]:

init_printing(use_latex="mathjax")
integrate(3/4, (x,1,2))

Out[55]:

$\displaystyle 0.75$

localhost:8890/lab 4/4

You might also like