In [13]:
import numpy as np # importando numpy
from scipy import stats # importando scipy.stats
import pandas as pd # importando pandas
import matplotlib.pyplot as plt # importando matplotlib
np.random.seed(10) # para poder replicar el random
# Graficos embebidos.
%matplotlib inline
In [38]:
# Ejemplo de grafico de cajas en python
datos_1 = np.random.normal(100, 10, 200)
datos_2 = np.random.normal(80, 30, 200)
datos_3 = np.random.normal(90, 20, 200)
datos_4 = np.random.normal(70, 25, 200)
datos_graf = [datos_1, datos_2, datos_3, datos_4]
# Creando el objeto figura
fig = plt.figure(1, figsize=(9, 6))
# Creando el subgrafico
ax = fig.add_subplot(111)
# creando el grafico de cajas
bp = ax.boxplot(datos_graf)
# visualizar mas facil los atípicos
x_pl = 1
for flier in bp['fliers']:
fdata = flier.get_data()
for y in fdata[1]:
ax.annotate('%.2f' % y, xy=(x_pl, y), textcoords='data')
x_pl = x_pl +1
flier.set(marker='o', color='red')
# los puntos aislados son valores atípicos
In [35]:
fdata[0]
Out[35]:
array([], dtype=float64)
In [8]:
datos_graf
Out[8]:
[array([ 100.21043221, 101.56371522, 110.3765419 , 100.456659 ,
111.07336149, 86.62210949, 97.46333278, 112.5487984 ,
99.19454832, 87.79157745, 88.44073915, 92.42660148,
86.87608593, 104.95348507, 71.84938692, 91.78621698,
86.0934942 , 86.26757327, 94.30448307, 87.65066623,
104.7759765 , 92.1052086 , 94.47764723, 108.3763692 ,
102.72717817, 101.26255476, 99.74141578, 88.7565778 ,
103.01572789, 121.18591436, 97.37033863, 89.96612056,
84.82203775, 80.78005096, 96.56654751, 94.59635669,
110.45169505, 99.20064763, 106.61394965, 106.23388411,
111.98601831, 96.91219186, 109.70167989, 104.51046213,
89.37293279, 89.74857963, 104.19614024, 96.8466772 ,
77.89245588, 102.56789835, 102.60529355, 101.98179914,
115.2585204 , 96.01727746, 84.63604791, 106.34149065,
101.54902806, 106.00676777, 106.47285486, 101.49564405,
94.48657432, 99.34497588, 98.4188327 , 95.43684821,
101.56872113, 98.80205232, 100.48742711, 89.09821417,
97.14364353, 88.53468124, 89.41501512, 113.76798342,
89.83150741, 104.8559977 , 83.15922597, 98.96436496,
110.42891713, 107.84855735, 92.58510765, 107.93741248,
96.27584254, 90.3267391 , 87.9233076 , 79.92024807,
104.69496206, 107.75654222, 116.71066492, 96.48760021,
96.72300301, 94.41118107, 103.12269976, 101.56715587,
84.94973252, 104.77145649, 105.71007366, 102.54069456,
97.58761183, 80.83113406, 101.01195085, 98.93197239,
95.3401611 , 100.67767263, 97.7553323 , 100.71738306,
98.83238437, 95.30141345, 88.90791505, 87.61540608,
103.41387654, 99.63032469, 104.06959694, 104.36534959,
98.71095714, 119.15652589, 94.97723558, 100.67693609,
94.92470007, 96.40956177, 89.66203932, 106.80045198,
94.69997436, 106.55596991, 110.64128646, 99.78735081,
94.68580042, 103.09762224, 105.65386249, 106.49446035,
86.7241084 , 115.05019928, 91.21188491, 86.19784325,
106.15319945, 96.55451223, 101.09433256, 102.15277935,
117.2038687 , 101.49422259, 104.69691984, 96.60677882,
92.95089107, 108.62025849, 105.87849672, 115.75342085,
92.29112981, 103.71280833, 107.7146975 , 83.31367334,
87.25831593, 104.92167749, 102.31822232, 93.61307518,
109.10932388, 91.04524764, 85.59427699, 100.84982872,
101.32168149, 109.46298664, 102.2422744 , 108.33514688,
90.31010749, 108.64170548, 89.55616853, 110.27838929,
98.03172285, 99.91832212, 95.85880503, 98.71186258,
96.80920321, 85.38586358, 91.71589301, 93.74698451,
102.66786015, 105.26014693, 96.91907608, 103.84037785,
104.50691682, 96.90564375, 75.65791325, 100.34880458,
114.54018342, 94.59743579, 107.40152039, 92.91710061,
93.4227193 , 121.11098537, 99.27033063, 90.57606873,
111.45008658, 103.10876375, 103.92133801, 81.05406112,
96.5848836 , 100.69773714, 98.39642932, 89.85660824,
96.68172251, 114.40697402, 96.09782136, 106.42450624]),
array([ 125.39756678, 75.72999235, 75.81740116, 115.26522628,
115.51367043, 100.50221782, 43.54659202, 95.94683719,
87.3628695 , 87.55963412, 132.33379973, 51.25699495,
134.74006867, 29.60163852, 46.56773233, 81.77453081,
70.52896175, 94.11296375, 103.29177214, 48.06129188,
74.52173186, 86.34343577, 40.01824224, 73.77290225,
79.76512353, 90.95798724, 67.99916051, 113.97576461,
77.04151122, 73.6693342 , 32.59286825, 52.11007328,
62.06289172, 37.0108801 , 65.99124295, 53.1756569 ,
-19.53007157, 106.85838751, 115.98888193, 91.44813805,
82.70518592, 78.87654141, 10.00477908, 77.99151247,
36.40672692, 50.85562784, 38.07235152, 82.57676261,
159.52069643, 65.45240706, 121.10297678, 93.64103495,
127.3565983 , 115.88540212, 24.82476264, 113.2814395 ,
96.4453254 , 45.44838513, 92.29146189, 37.16037468,
85.87679966, 114.7460757 , 87.18058794, 43.78588091,
71.07409407, 90.44436336, 104.54860493, 86.01502089,
69.03381297, 63.37507938, 94.45114518, 129.03508023,
101.06184055, 60.70200341, 117.23337081, 77.07760045,
124.8361283 , 77.76141011, 112.80579887, 70.68531534,
75.65076449, 123.24427628, 41.79004711, 87.2062228 ,
62.85529382, 88.71266769, 83.65827381, 149.52671225,
90.57838872, 43.6069922 , 67.83987877, 101.50365129,
70.73316782, 101.52734772, 121.20120496, 109.24760154,
46.82209092, 62.86430362, 82.60619806, 26.60609513,
101.46909018, 72.11156263, 74.7764959 , 90.61672634,
62.38211523, 125.3586155 , 102.64734142, 40.61131681,
81.64332206, 63.95579013, 104.19172981, 102.48644434,
121.3801439 , 65.85216159, 71.74078954, 87.16451727,
90.51574078, 60.6003116 , 101.44513227, 77.80616482,
6.13332263, 7.66305285, 50.12159113, 125.83670524,
107.36028911, 90.05995873, 67.83120219, 76.67352912,
96.8048113 , 68.68045755, 118.84187018, 125.28118876,
113.09993774, 62.23943836, 75.98598733, 78.20687361,
88.79187128, 37.67505719, 117.62773223, 53.29170263,
85.13040632, 81.76266141, 73.77021189, 114.90757386,
91.07648034, 107.14321764, 102.86937044, 59.55327563,
121.33470382, 115.53664373, 50.53810176, 72.48617543,
70.40987102, 89.6717752 , 94.03735982, 149.72146236,
55.28141851, 70.93641547, 117.07800455, 115.72082518,
57.50311911, 104.4566607 , 69.11355742, 99.29685242,
99.6819208 , 132.14258047, 34.31462741, 56.647892 ,
97.38899167, 48.18993418, 63.53454319, 108.25683742,
54.66972573, 62.55182999, 79.88083641, 35.58770175,
144.95787467, 46.28259527, 21.6345092 , 76.30966834,
65.73064597, 103.76569258, 111.47691414, 35.02512254,
47.71427098, 49.39211453, 146.54812984, 76.81646203,
127.09782519, 82.35586445, 81.16751052, 37.05097726,
79.28388356, 111.03052107, 83.98753597, 92.60572216,
90.51329019, 153.44014412, 56.48674006, 102.95741924]),
array([ 104.11920088, 104.45973665, 125.16945849, 78.93781318,
77.87941847, 93.80945229, 102.81404161, 64.85594456,
88.80594797, 80.14273961, 119.3102538 , 121.85928581,
90.9958473 , 110.41963856, 51.27593424, 81.4322768 ,
62.58327418, 85.84544774, 107.49952855, 78.46059364,
90.08433449, 129.38088389, 100.23755323, 145.86331523,
88.44776608, 53.09347268, 99.97078133, 85.35596744,
61.4466061 , 72.39424547, 54.47991172, 131.17054719,
58.41495326, 128.28201459, 83.01703751, 92.12283443,
96.62201643, 110.23811681, 55.66368835, 93.36863938,
49.00778946, 98.19386651, 77.71893677, 84.10582002,
114.83304379, 53.58911748, 88.72992862, 99.61134926,
94.09665177, 129.66483172, 100.54078661, 68.34762786,
81.50158567, 86.47116155, 110.13565588, 106.57229662,
96.63182469, 99.32181278, 96.90751507, 98.178724 ,
96.82906604, 129.21033302, 110.96952522, 108.72176526,
104.06542142, 105.92405224, 61.46582315, 100.25605596,
73.190792 , 126.55220415, 94.65592693, 95.9835079 ,
122.42195445, 73.27398115, 62.51430125, 98.47649115,
100.04811615, 102.22845623, 84.42051294, 96.73943735,
79.33793142, 61.96845314, 104.45008802, 92.33754179,
63.14531816, 60.64471287, 67.21896886, 97.3879188 ,
71.4653226 , 95.86987656, 62.48434162, 84.86768066,
98.23852581, 72.71626392, 76.11688779, 63.18235393,
110.79955915, 80.18720959, 90.6081551 , 54.4233368 ,
77.94580389, 91.04532999, 104.13117308, 91.54075221,
54.59321386, 88.99718729, 89.67754227, 97.84450173,
100.03273072, 71.45275804, 88.56599228, 102.63677656,
105.40837941, 71.44184998, 74.82550062, 94.90661416,
82.65770672, 84.24831096, 106.93349847, 92.98910989,
101.65789639, 102.27786145, 68.56304104, 104.76786726,
89.07110271, 57.8099926 , 94.74091242, 94.72888538,
97.18510975, 79.66939627, 109.7005354 , 74.41483905,
82.08231691, 111.66369702, 99.86588906, 94.64513998,
124.56777171, 85.32514803, 53.05836803, 94.35787894,
81.98464066, 83.119707 , 72.00756332, 69.41401006,
77.30891866, 97.83728967, 66.48379682, 99.86228955,
79.12088725, 93.05713925, 120.10126124, 80.51899485,
94.19102053, 87.29043105, 109.82867285, 59.88016626,
97.90499049, 80.11843704, 62.95347098, 71.40363419,
79.26891467, 93.22520425, 95.45957122, 106.13015207,
72.35270926, 88.39438839, 92.69640261, 104.88926844,
69.82086464, 87.06819639, 60.1156073 , 84.08204119,
67.57852918, 73.03190903, 95.39706751, 86.85865498,
75.45071145, 115.45448424, 108.52213873, 89.03885168,
76.27451955, 101.57916992, 80.69413599, 86.57165331,
100.23177529, 85.32944648, 45.08885274, 92.37484875,
113.63538099, 96.61217893, 77.16861651, 122.01243874,
65.04173875, 121.19320936, 81.87847541, 62.01497066,
102.06728968, 105.3391864 , 97.2361336 , 102.06561909]),
array([ 97.56380901, 80.27346043, 99.98835838, 81.96723134,
89.62497189, 59.19291624, 57.93131457, 45.46436299,
88.12074477, 55.92534863, 62.12956776, 63.3715557 ,
65.06285937, 10.58105556, 40.592524 , 80.76627484,
25.86016872, 100.35283878, 81.39425265, 56.67067319,
66.98905628, 67.02361889, 87.48250169, 77.97925607,
98.46104207, 109.42113732, 98.7910926 , 64.61201542,
82.78364869, 70.91327517, 85.1164312 , 7.46722486,
30.10605894, 131.40769559, 81.91059952, 108.53833449,
97.7082626 , 54.67945756, 55.68177691, 76.86937782,
71.77963426, 42.62660034, 27.27787289, 84.22865608,
93.46670232, 31.34037484, 69.33235546, 125.16404665,
53.98167642, 72.11839571, 73.68952636, 106.58808386,
56.34910479, 44.61447729, 113.4941773 , 83.68314243,
40.50652421, 56.5006627 , 48.95064772, 92.3056889 ,
40.25442665, 93.33456202, 101.16501866, 83.11976148,
48.00936182, 65.9123838 , 111.93956852, 55.4107952 ,
77.2041074 , 109.20449236, 57.69944282, 92.41496327,
128.95392875, 96.00036463, 72.69925743, 74.79464159,
50.13317673, 86.33693918, 68.37131928, 28.35632143,
79.00638082, 45.11297386, 80.56273897, 125.55879732,
48.50826027, 76.78925965, 80.76350696, 59.9078915 ,
96.78003969, 92.60615081, 65.35765918, 59.26391913,
45.67923537, 105.76226625, 68.2351919 , 90.07127305,
62.45922747, 56.05246982, 39.24645206, 60.87720607,
96.97521224, 63.39560823, 87.82808449, 119.75562945,
94.03398519, 66.17874389, 132.3725352 , 58.43881196,
48.16608706, 50.07307615, 91.33087192, 51.73462598,
79.57978044, 122.64022092, 81.47000981, 58.88614947,
62.02156151, 37.31602326, 95.68249841, 114.87370609,
102.28411571, 55.78643709, 68.63812895, 36.18501215,
88.3079671 , 43.90194085, 78.15753049, 73.72089481,
80.97338428, 59.56114382, 71.46203263, 58.91243499,
25.3130141 , 43.92258981, 61.81989236, 106.35186547,
124.37715925, 82.71559619, 91.88350644, 59.20951896,
46.16800406, 83.06409856, 49.34820729, 60.88750181,
96.68295281, 75.88403663, 70.58558043, 75.45072839,
39.70701456, 70.06672118, 77.72230095, 58.86182219,
67.85953163, 65.00364232, 79.66777727, 96.31157856,
91.21672934, 71.52396551, -7.81612359, 64.57468288,
105.30392836, 81.59049327, 37.17797794, 76.09680358,
105.96669087, 44.9098821 , 53.40115529, 100.05147836,
64.63553848, 65.13028127, 98.8878071 , 87.48786627,
120.33804104, 67.93504114, 117.70936534, 67.98685462,
48.21551293, 45.8044086 , 30.87911477, 41.07436232,
35.20166421, 82.13508042, 57.63762906, 121.41854825,
41.48073263, 60.34513703, 95.52220283, 78.79518573,
97.061025 , 52.29766 , 88.08042449, 42.24298221,
102.20115127, 44.89998959, 24.16793981, 77.10748519,
70.80575567, 38.24213726, 60.83083228, 34.21584738])]
In [ ]:
Content source: relopezbriega/mi-python-blog
Similar notebooks: