Numpy NP Pandas PD Matplotlib - Pyplot PLT: Import As Import As Import As Matplotlib

You might also like

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

In [ ]:

In [107]:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

In [69]:

from random import randint


income = [randint(0, 10000) for i in range(1000)]

In [3]:

income[100:110]

Out[3]:

[41555, 82746, 67628, 67742, 53496, 51186, 9397, 85779, 1941, 75908]

In [108]:

plt.hist(x=income)

Out[108]:

(array([ 93., 74., 100., 90., 116., 90., 114., 111., 107., 105.]),
array([1.0000e+00, 9.9930e+02, 1.9976e+03, 2.9959e+03, 3.9942e+03,
4.9925e+03, 5.9908e+03, 6.9891e+03, 7.9874e+03, 8.9857e+03,
9.9840e+03]),
<a list of 10 Patch objects>)
In [109]:

plt.figure(figsize=(12,6))
plt.hist(x = income)

Out[109]:

(array([ 93., 74., 100., 90., 116., 90., 114., 111., 107., 105.]),
array([1.0000e+00, 9.9930e+02, 1.9976e+03, 2.9959e+03, 3.9942e+03,
4.9925e+03, 5.9908e+03, 6.9891e+03, 7.9874e+03, 8.9857e+03,
9.9840e+03]),
<a list of 10 Patch objects>)

In [110]:

plt.figure(figsize=(12,6))
plt.hist(x = income, label = 'Frequency Distribution')
plt.legend()
plt.xlabel('Worth')
plt.ylabel('Frequency')

Out[110]:

Text(0, 0.5, 'Frequency')


In [111]:

plt.figure(figsize=(12,6))
plt.hist(x = income, label = 'Frequency Distribution', edgecolor='white')
plt.legend()
plt.xlabel('Worth')
plt.ylabel('Frequency')

Out[111]:

Text(0, 0.5, 'Frequency')

In [112]:

plt.figure(figsize=(12,6))
plt.hist(x = income, label = 'Frequency Distribution', edgecolor='white', color='#CCAAC
C')
plt.legend()
plt.xlabel('Worth')
plt.ylabel('Frequency')

Out[112]:

Text(0, 0.5, 'Frequency')


In [113]:

plt.figure(figsize=(12,6))
plt.hist(x = income, label = 'Frequency Distribution', edgecolor='white', color='#CCAAC
C', bins=20)
plt.legend()
plt.xlabel('Worth')
plt.ylabel('Frequency')
Out[113]:

Text(0, 0.5, 'Frequency')

In [114]:

[i for i in range(10)]

Out[114]:

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
In [115]:

plt.figure(figsize=(12,6))
plt.hist(x = income, label = 'Frequency Distribution', edgecolor='white', color='#CCAAC
C', bins=[i for i in range(0,10001, 500)])
plt.legend()
plt.xlabel('Worth')
plt.ylabel('Frequency')

Out[115]:

Text(0, 0.5, 'Frequency')


In [117]:

plt.figure(figsize=(12,6))
plt.hist(x = income, label = 'Frequency Distribution', edgecolor='white', color='#CCAAC
C', bins=[i for i in range(0,10001, 500)])
plt.legend()
plt.xticks([i for i in range(0,10001,500)])
plt.xlabel('Worth')
plt.ylabel('Frequency')

Out[117]:

Text(0, 0.5, 'Frequency')


In [118]:

plt.figure(figsize=(12,6))
plt.hist(x = income, label = 'Probability Density', edgecolor='white', color='#CCAACC',
bins=[i for i in range(0,10001, 500)], density=True)
plt.legend()
plt.xticks([i for i in range(0,10001,500)])
plt.xlabel('Worth')
plt.ylabel('Probability')

Out[118]:

Text(0, 0.5, 'Probability')


In [119]:

plt.figure(figsize=(12,6))
plt.hist(x = income, label = 'Cumulative Density', edgecolor='white', color='#CCAACC',
bins=[i for i in range(0,10001, 500)], density=True, cumulative=True)
plt.legend()
plt.xticks([i for i in range(0,10001,500)])
plt.xlabel('Worth')
plt.ylabel('Cumulative Probability')

Out[119]:

Text(0, 0.5, 'Cumulative Probability')


In [121]:

plt.figure(figsize=(12,6))
plt.hist(x = income,
label = 'Cumulative Density',
edgecolor = 'black',
color='#AACCAA',
bins=[i for i in range(0,10001, 500)],
density=True,
cumulative=True,
histtype='step')
plt.legend(loc=2)
plt.xticks([i for i in range(0,10001,500)])
plt.xlabel('Worth')
plt.ylabel('Cumulative Probability')

Out[121]:

Text(0, 0.5, 'Cumulative Probability')

In [122]:

nparr = np.random.normal(0,1,1000)

In [123]:

nparr = [i for i in nparr]


In [124]:

plt.figure(figsize=(9,5))
plt.hist(x = nparr, label = 'Normal Distribution', edgecolor='white', color='#CCAACC',
bins = 15, density=True)
plt.legend()

Out[124]:

<matplotlib.legend.Legend at 0x25795f5d0b8>

In [ ]:

In [125]:

import seaborn as sns

In [126]:

tips = sns.load_dataset('tips')

In [127]:

type(tips)

Out[127]:

pandas.core.frame.DataFrame
In [128]:

tips.head()

Out[128]:

total_bill tip sex smoker day time size

0 16.99 1.01 Female No Sun Dinner 2

1 10.34 1.66 Male No Sun Dinner 3

2 21.01 3.50 Male No Sun Dinner 3

3 23.68 3.31 Male No Sun Dinner 2

4 24.59 3.61 Female No Sun Dinner 4

In [129]:

tips.hist('total_bill', edgecolor='white', figsize=(10,5), grid=False)

Out[129]:

array([[<matplotlib.axes._subplots.AxesSubplot object at 0x0000025795ED26D


8>]],
dtype=object)

In [ ]:

You might also like