Data Vis
Data Vis
In [74]:
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
In [75]:
#Graph Styling
# https://tonysyu.github.io/raw_content/matplotlib-style-gallery/gallery.html
plt.style.use('seaborn-darkgrid')
Line Graphs
In [76]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 1/79
4/5/2020 Matplotlib
In [77]:
In [78]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 2/79
4/5/2020 Matplotlib
In [79]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 3/79
4/5/2020 Matplotlib
In [80]:
plt.style.use('seaborn-darkgrid')
%matplotlib inline
In [81]:
plt.figure(figsize=(10,5))
x = np.linspace(0, 10, 1000)
y = np.sin(x) # Sine Graph
plt.plot(x,y)
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 4/79
4/5/2020 Matplotlib
In [82]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 5/79
4/5/2020 Matplotlib
In [83]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 6/79
4/5/2020 Matplotlib
In [84]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 7/79
4/5/2020 Matplotlib
In [85]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 8/79
4/5/2020 Matplotlib
In [86]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 9/79
4/5/2020 Matplotlib
In [115]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 10/79
4/5/2020 Matplotlib
In [88]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 11/79
4/5/2020 Matplotlib
In [116]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 12/79
4/5/2020 Matplotlib
In [117]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 13/79
4/5/2020 Matplotlib
In [118]:
# Line Styling
x = np.linspace(0, 10, 2000)
plt.figure(figsize=(16, 9))
plt.plot(x,np.sin(x) , label = '$Sin(X) $ $ Dashed $' , linestyle='dashed')
plt.plot(x+1,np.sin(x) , label = '$Sin(X) $ $ Dashdot $' , linestyle='dashdot')
plt.plot(x,np.cos(x) , label = '$cos(X) $ $ Solid $' , linestyle='solid')
plt.plot(x+1,np.cos(x) , label = '$cos(X)$ $ Dotted $' , linestyle='dotted')
plt.xlabel(r'$X$' , fontsize = 18)
plt.ylabel(r'$Y$' , fontsize = 18)
plt.title("$Sin(x) $ $ & $ $ Cos(x)$" ,fontsize = 14)
plt.legend(loc = 'upper right' , fontsize = 14 , bbox_to_anchor=(1.2, 1.0)) # Legend will b
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 14/79
4/5/2020 Matplotlib
In [119]:
# Line Styling
x = np.linspace(0, 10, 2000)
plt.figure(figsize=(16, 9))
plt.plot(x,np.sin(x) , label = '$Sin(X) $ $ Dashed $' , linestyle='--')
plt.plot(x+1,np.sin(x) , label = '$Sin(X) $ $ Dashdot $' , linestyle='-.')
plt.plot(x,np.cos(x) , label = '$cos(X) $ $ Solid $' , linestyle='-')
plt.plot(x+1,np.cos(x) , label = '$cos(X)$ $ Dotted $' , linestyle=':')
plt.xlabel(r'$X$' , fontsize = 18)
plt.ylabel(r'$Y$' , fontsize = 18)
plt.title("$Sin(x) $ $ & $ $ Cos(x)$" ,fontsize = 14)
plt.legend(loc = 'upper right' , fontsize = 14 , bbox_to_anchor=(1.2, 1.0)) # Legend will b
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 15/79
4/5/2020 Matplotlib
In [93]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 16/79
4/5/2020 Matplotlib
In [94]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 17/79
4/5/2020 Matplotlib
In [95]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 18/79
4/5/2020 Matplotlib
In [96]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 19/79
4/5/2020 Matplotlib
In [97]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 20/79
4/5/2020 Matplotlib
In [110]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 21/79
4/5/2020 Matplotlib
In [112]:
plt.figure(figsize=(12,6))
x = np.linspace(0, 10, 100)
y1 = np.sin(x) # Sine Graph
y2 = np.cos(x) # cosine graph
plt.subplot(2,1,1)
plt.plot(x,y1, "b-")
plt.subplot(2,1,2)
plt.plot(x,y2, "r-")
plt.tight_layout()
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 22/79
4/5/2020 Matplotlib
In [113]:
ax1[0,1].plot(x,y2,"tab:orange")
ax1[0,1].set_title("Cubic Function")
ax1[0,1].set_xlabel(r'$X$' , fontsize = 18)
ax1[0,1].set_ylabel(r'$Y$' , fontsize = 18)
ax1[0,2].plot(x,y3,"tab:green")
ax1[0,2].set_title("Sine Function")
ax1[0,2].set_xlabel(r'$X$' , fontsize = 18)
ax1[0,2].set_ylabel(r'$Y$' , fontsize = 18)
ax1[1,0].plot(x,y4,"b-")
ax1[1,0].set_title("Cosine Function")
ax1[1,0].set_xlabel(r'$X$' , fontsize = 18)
ax1[1,0].set_ylabel(r'$Y$' , fontsize = 18)
ax1[1,1].plot(x,y5,"r-")
ax1[1,1].set_title("Tangent Function")
ax1[1,1].set_xlabel(r'$X$' , fontsize = 18)
ax1[1,1].set_ylabel(r'$Y$' , fontsize = 18)
ax1[1,2].plot(x,y6,"g-")
ax1[1,2].set_title("Hyperbolic Tangent")
ax1[1,2].set_xlabel(r'$X$' , fontsize = 18)
ax1[1,2].set_ylabel(r'$Y$' , fontsize = 18)
ax1[2,0].plot(x,y7,"m-")
ax1[2,0].set_title("Hyperbolic Sine")
ax1[2,0].set_xlabel(r'$X$' , fontsize = 18)
ax1[2,0].set_ylabel(r'$Y$' , fontsize = 18)
ax1[2,1].plot(x,y8,"y-")
ax1[2,1].set_title("Hyperbolic Cosine")
ax1[2,1].set_xlabel(r'$X$' , fontsize = 18)
ax1[2,1].set_ylabel(r'$Y$' , fontsize = 18)
ax1[2,2].plot(x,y9,"k-")
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 23/79
4/5/2020 Matplotlib
ax1[2,2].set_title("Exponential Function")
ax1[2,2].set_xlabel(r'$X$' , fontsize = 18)
ax1[2,2].set_ylabel(r'$Y$' , fontsize = 18)
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 24/79
4/5/2020 Matplotlib
In [114]:
y = [[1,2,3,4,5] , [10,20,30,40,50],[60,70,80,90,100] ]
cnt =0
plt.figure(figsize=(10,6))
for i in y:
x1 = [10,20,30,40,50]
cnt +=1
print ('iteration Number :- {}'.format(cnt))
print ('X1 Value :- {}'.format(x1))
print('Y value (i) :- {}'.format(i))
plt.plot(x1,i)
plt.show()
iteration Number :- 1
X1 Value :- [10, 20, 30, 40, 50]
Y value (i) :- [1, 2, 3, 4, 5]
iteration Number :- 2
X1 Value :- [10, 20, 30, 40, 50]
Y value (i) :- [10, 20, 30, 40, 50]
iteration Number :- 3
X1 Value :- [10, 20, 30, 40, 50]
Y value (i) :- [60, 70, 80, 90, 100]
Bar Graphs
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 25/79
4/5/2020 Matplotlib
In [288]:
id1 = np.arange(1,10)
score = np.arange(20,110,10)
plt.bar(id1,score)
plt.xlabel('Student ID')
plt.ylabel('Score')
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 26/79
4/5/2020 Matplotlib
In [289]:
id1 = np.arange(1,10)
score = np.arange(20,110,10)
plt.figure(figsize=(8,5)) # Setting the figure size
ax = plt.axes()
ax.set_facecolor("#ECF0F1") # Setting the background color by specifying the HEX Code
plt.bar(id1,score,color = '#FFA726')
plt.xlabel(r'$Student $ $ ID$')
plt.ylabel(r'$Score$')
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 27/79
4/5/2020 Matplotlib
In [290]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 28/79
4/5/2020 Matplotlib
In [291]:
In [293]:
Out[293]:
[]
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 29/79
4/5/2020 Matplotlib
In [294]:
Out[294]:
[]
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 30/79
4/5/2020 Matplotlib
In [295]:
x = np.arange(1,21)
plt.figure(figsize=(16,8))
y1 = np.random.uniform(0.1,0.7,20)
y2 = np.random.uniform(0.1,0.7,20)
plt.xlim(0,21)
plt.ylim(-1.25,+1.25)
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 31/79
4/5/2020 Matplotlib
In [296]:
plt.style.use('seaborn-darkgrid')
x1= ['Asif','Basit','Ravi','Minil']
y1= [17,18,29,40]
y2 = [20,21,22,23]
plt.figure(figsize=(5,7))
plt.bar(x1,y1,label = "Open Tickets",width = 0.5,color = '#FF6F00')
plt.bar(x1,y2,label = "Closed Tickets",width = 0.5 ,bottom = y1 , color = '#FFB300')
plt.xlabel('$X$')
plt.ylabel('$Y$')
plt.title ('$Bar $ $ Chart$')
plt.legend()
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 32/79
4/5/2020 Matplotlib
In [297]:
plt.style.use('seaborn-darkgrid')
x1= ['Asif','Basit','Ravi','Minil']
y1= np.array([17,18,29,40])
y2 =np.array([20,21,22,23])
y3 =np.array([5,9,11,12])
plt.figure(figsize=(5,7))
plt.bar(x1,y1,label = "Open Tickets",width = 0.5,color = '#FF6F00')
plt.bar(x1,y2,label = "Closed Tickets",width = 0.5 ,bottom = y1 , color = '#FFB300')
plt.bar(x1,y3,label = "Cancelled Tickets",width = 0.5 ,bottom = y1+y2 , color = '#F7DC6F')
plt.xlabel('$X$')
plt.ylabel('$Y$')
plt.title ('$Bar $ $ Chart$')
plt.legend()
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 33/79
4/5/2020 Matplotlib
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 34/79
4/5/2020 Matplotlib
In [298]:
plt.figure(figsize=(7,9))
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 35/79
4/5/2020 Matplotlib
Out[298]:
array([0, 1, 2, 3])
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 36/79
4/5/2020 Matplotlib
In [299]:
plt.style.use('seaborn-darkgrid')
x1= ['Asif','Basit','Ravi','Minil']
y1= [17,18,29,40]
y2 = [20,21,22,23]
plt.figure(figsize=(8,5))
plt.barh(x1,y1,label = "Open Tickets",color = '#FF6F00')
plt.barh(x1,y2,label = "Closed Tickets", left = y1 , color = '#FFB300')
plt.xlabel('$X$')
plt.ylabel('$Y$')
plt.title ('$Bar $ $ Chart$')
plt.legend()
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 37/79
4/5/2020 Matplotlib
In [300]:
plt.legend()
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 38/79
4/5/2020 Matplotlib
In [301]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 39/79
4/5/2020 Matplotlib
In [302]:
# Displaying values at the top of the Grouped Bar Chart using plt.text()
plt.figure(figsize=(7,9))
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 40/79
4/5/2020 Matplotlib
Scatter Graphs
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 41/79
4/5/2020 Matplotlib
In [303]:
x1 = np.array([250,150,350,252,450,550,455,358,158,355])
y1 =np.array([40,50,80, 90, 100,50,60,88,54,45])
x2 = np.array([200,100,300,220,400,500,450,380,180,350])
y2 = np.array([400,500,800, 900, 1000,500,600,808,504,405])
#Graph - 1
plt.scatter(x1,y1)
plt.xlabel('$Time $ $ Spent$' , fontsize = 12)
plt.ylabel('$Score$' , fontsize = 12)
plt.title ('Scatter Graph')
plt.show()
#Graph - 2
plt.scatter(x2,y2 ,color = 'r')
plt.xlabel('$Time $ $ Spent$' , fontsize = 12)
plt.ylabel('$Score$' , fontsize = 12)
plt.title ('Scatter Graph')
plt.show()
#Graph - 3
plt.scatter(x1,y1 ,label = 'Class 1')
plt.scatter(x2,y2 ,label = 'Class 2',color ='r')
plt.xlabel('$Time $ $ Spent$' , fontsize = 12)
plt.ylabel('$Score$' , fontsize = 12)
plt.title ('Scatter Graph')
plt.legend()
plt.show()
#Graph - 4
plt.scatter(x1,y1 ,label = 'Class 1',marker='o' , color = 'm')
plt.scatter(x2,y2 ,label = 'Class 2',marker='v',color ='r')
plt.xlabel('$Time $ $ Spent$' , fontsize = 12)
plt.ylabel('$Score$' , fontsize = 12)
plt.title ('Scatter Graph')
plt.legend()
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 42/79
4/5/2020 Matplotlib
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 43/79
4/5/2020 Matplotlib
In [304]:
plt.figure(figsize=(10,6))
x = np.random.normal(0,10,1000)
y = np.random.normal(0,10,1000)
plt.scatter(x,y)
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 44/79
4/5/2020 Matplotlib
In [305]:
plt.figure(figsize=(8,6))
x = np.random.random(10)
y = np.random.random(10)
# "alpha" is used for softnening colors
plt.scatter(np.random.random(10),np.random.random(10),c='r', s=50 , alpha=0.6 , label = 'On
plt.scatter(np.random.random(10),np.random.random(10),c='b', s=100 , alpha=0.6 , label = 'T
plt.scatter(np.random.random(10),np.random.random(10),c='g', s=150 , alpha=0.6 , label = 'T
plt.scatter(np.random.random(10),np.random.random(10),c='y', s=200 , alpha=0.6 , label = 'F
plt.legend(bbox_to_anchor=(1.0, 1.0) , shadow=True, fontsize='x-large')
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 45/79
4/5/2020 Matplotlib
In [306]:
In [307]:
Pie Charts
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 46/79
4/5/2020 Matplotlib
In [308]:
plt.figure(figsize=(9,9))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
plt.pie (area , labels= labels , colors= colors , startangle=45)
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 47/79
4/5/2020 Matplotlib
In [309]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 48/79
4/5/2020 Matplotlib
In [310]:
plt.figure(figsize=(8,8))
area = [48 , 30 , 20 , 15]
total = np.sum(area)
labels = ['Low' , 'Medium' , 'High' , 'Critical']
def val_per(x):
return '{:.2f}%\n({:.0f})'.format(x, total*x/100)
colors = ['#7CB342','#C0CA33','#FFB300','#F57C00']
plt.pie (area , labels= labels , colors= colors , startangle=45 , shadow='true', autopct=va
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 49/79
4/5/2020 Matplotlib
In [311]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 50/79
4/5/2020 Matplotlib
In [312]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 51/79
4/5/2020 Matplotlib
Donut plot
In [313]:
plt.figure(figsize=(9,9))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
plt.pie (area , labels= labels , colors= colors , startangle=45)
my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 52/79
4/5/2020 Matplotlib
In [314]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 53/79
4/5/2020 Matplotlib
In [315]:
plt.figure(figsize=(9,9))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
plt.pie (area , labels= labels , colors= colors , startangle=45 , explode=[0,0 , 0.0 , 0.1]
my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 54/79
4/5/2020 Matplotlib
In [316]:
plt.figure(figsize=(9,9))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
plt.pie (area , labels= labels , colors= colors , startangle=45 , explode=[0,0 , 0.1 , 0.1]
my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 55/79
4/5/2020 Matplotlib
In [317]:
plt.figure(figsize=(9,9))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
plt.pie (area , labels= labels , colors= colors , startangle=45 , explode=[0.03,0.03 , 0.03
my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 56/79
4/5/2020 Matplotlib
In [318]:
plt.figure(figsize=(9,9))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
plt.pie (area , labels= labels , colors= colors , startangle=45 , autopct='%1.1f%%', explod
my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 57/79
4/5/2020 Matplotlib
In [319]:
plt.figure(figsize=(9,9))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
plt.pie (area , labels= labels , colors= colors , startangle=45 , autopct='%1.1f%%', pctdis
my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 58/79
4/5/2020 Matplotlib
In [320]:
plt.figure(figsize=(9,9))
area = [48 , 30 , 20 , 15]
total = np.sum(area)
def val_per(x):
return '{:.2f}%\n({:.0f})'.format(x, total*x/100)
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 59/79
4/5/2020 Matplotlib
In [321]:
fig = plt.figure(figsize=(20,6))
area = [48 , 30 , 20 , 15]
priority = ['Low' , 'Medium' , 'High' , 'Critical']
status = ['Resolved' , 'Cancelled' , 'Pending' , 'Assigned']
company = ['IBM' , 'Microsoft', 'BMC' , 'Apple']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
plt.subplot(1,3,1)
plt.pie (area , labels= priority , colors= colors , startangle=45)
my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.subplot(1,3,2)
plt.pie (area , labels= status , colors= colors , startangle=45)
my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.subplot(1,3,3)
plt.pie (area , labels= company , colors= colors , startangle=45)
my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 60/79
4/5/2020 Matplotlib
In [322]:
fig = plt.figure(figsize=(20,13))
area = [48 , 30 , 20 , 15]
priority = ['Low' , 'Medium' , 'High' , 'Critical']
status = ['Resolved' , 'Cancelled' , 'Pending' , 'Assigned']
company = ['IBM' , 'Microsoft', 'BMC' , 'Apple']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
plt.subplot(2,3,1)
plt.pie (area , labels= priority , colors= colors , startangle=45)
my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.subplot(2,3,2)
plt.pie (area , labels= status , colors= colors , startangle=45)
my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.subplot(2,3,3)
plt.pie (area , labels= company , colors= colors , startangle=45)
my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.subplot(2,3,4)
plt.pie (area , labels= priority , colors= colors , startangle=45)
my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.subplot(2,3,5)
plt.pie (area , labels= status , colors= colors , startangle=45)
my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.subplot(2,3,6)
plt.pie (area , labels= company , colors= colors , startangle=45)
my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 61/79
4/5/2020 Matplotlib
Histogram
In [323]:
x = np.random.normal(size = 2000)
plt.hist(x, bins=40, color='yellowgreen')
plt.gca().set(title='Histogram', ylabel='Frequency')
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 62/79
4/5/2020 Matplotlib
In [324]:
x = np.random.rand(2000)
plt.hist(x, bins=30 ,color='#D4AC0D')
plt.gca().set(title='Histogram', ylabel='Frequency')
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 63/79
4/5/2020 Matplotlib
In [325]:
Binning
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 64/79
4/5/2020 Matplotlib
In [326]:
# Binning
plt.figure(figsize=(10,8))
x = np.random.normal(size = 2000)
plt.hist(x, bins=30, color='yellowgreen' , edgecolor="#6A9662")
plt.gca().set(title='Histogram', ylabel='Frequency')
plt.show()
plt.figure(figsize=(10,8))
plt.hist(x, bins=20, color='yellowgreen' , edgecolor="#6A9662")
plt.gca().set(title='Histogram', ylabel='Frequency')
plt.show()
plt.figure(figsize=(10,8))
plt.hist(x, bins=10, color='yellowgreen' , edgecolor="#6A9662")
plt.gca().set(title='Histogram', ylabel='Frequency')
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 65/79
4/5/2020 Matplotlib
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 66/79
4/5/2020 Matplotlib
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 67/79
4/5/2020 Matplotlib
In [329]:
plt.figure(figsize=(8,11))
x = np.random.normal(-4,1,size = 800)
y = np.random.normal(0,1.5,size = 800)
z = np.random.normal(3.5,1,size = 800)
plt.hist(x, bins=30, color='yellowgreen' , alpha=0.6)
plt.hist(y, bins=30, color='#FF8F00' , alpha=0.6)
plt.hist(z, bins=30, color='blue' , alpha=0.6)
plt.gca().set(title='Histogram', ylabel='Frequency')
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 68/79
4/5/2020 Matplotlib
In [330]:
Area Plot
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 69/79
4/5/2020 Matplotlib
In [331]:
x = np.arange(1,31)
y = np.random.normal(10,11,size=30)
y = np.square(y)
plt.figure(figsize=(16,6))
plt.plot(x,y)
plt.fill_between(x, y)
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 70/79
4/5/2020 Matplotlib
In [334]:
x = np.arange(1,31)
y = np.random.normal(10,11,size=30)
y = np.square(y)
plt.figure(figsize=(16,6))
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 71/79
4/5/2020 Matplotlib
In [336]:
x = np.arange(1,31)
y = np.random.normal(10,11,size=30)
y = np.square(y)
plt.figure(figsize=(16,6))
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 72/79
4/5/2020 Matplotlib
In [338]:
x = np.arange(1,51)
y = np.random.normal(1,5,size=50)
y = np.square(y)
plt.figure(figsize=(16,6))
plt.fill_between( x, y, color="#5ac8fa", alpha=0.4)
plt.plot(x, y, color="blue", alpha=0.6) # Bold line on edges
plt.title("$ Area $ $ chart $" , fontsize = 16)
plt.xlabel("$X$" , fontsize = 16)
plt.ylabel("$Y$" , fontsize = 16)
plt.show()
plt.figure(figsize=(16,6))
plt.fill_between( x, y, color="#5ac8fa", alpha=0.4)
plt.plot(x, y, color="blue", alpha=0.2) # Less stronger line on edges
plt.title("$ Area $ $ chart $" , fontsize = 14)
plt.xlabel("$X$" , fontsize = 14)
plt.ylabel("$Y$" , fontsize = 14)
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 73/79
4/5/2020 Matplotlib
In [339]:
x=np.arange(1,6)
y1 = np.array([1,5,9,13,17])
y2 = np.array([2,6,10,14,16])
y3 = np.array([3,7,11,15,19])
y4 = np.array([4,8,12,16,20])
plt.figure(figsize=(8,6))
plt.stackplot(x,y1,y2,y3,y4, labels=['Y1','Y2','Y3','Y4'])
plt.legend(loc='upper left')
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 74/79
4/5/2020 Matplotlib
In [340]:
x=np.arange(1,6)
y=[ [1,5,9,13,17], [2,6,10,14,16], [3,7,11,15,19] , [4,8,12,16,20] ]
plt.figure(figsize=(8,6))
plt.stackplot(x,y , labels=['Y1','Y2','Y3','Y4'])
plt.legend(loc='upper left')
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 75/79
4/5/2020 Matplotlib
In [341]:
x=np.arange(1,7)
y=[ [1,5,9,3,17,1], [2,6,10,4,16,2], [3,7,11,5,19,1] , [4,8,12,6,20,2] ]
plt.figure(figsize=(10,6))
plt.stackplot(x,y , labels=['Y1','Y2','Y3','Y4'])
plt.legend(loc='upper left')
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 76/79
4/5/2020 Matplotlib
In [342]:
x=np.arange(1,7)
y=[ [1,5,9,3,17,1], [2,6,10,4,16,2], [3,7,11,5,19,1] , [4,8,12,6,20,2] ]
plt.figure(figsize=(11,6))
plt.stackplot(x,y , labels=['Y1','Y2','Y3','Y4'] , colors= ["#00b159" , "#ffc425", "#f37735
plt.legend(loc='upper left')
plt.show()
plt.figure(figsize=(11,6))
plt.stackplot(x,y, labels=['Y1','Y2','Y3','Y4'], colors= ["#00b159" , "#ffc425", "#f37735",
plt.legend(loc='upper left')
plt.show()
plt.figure(figsize=(11,6))
plt.stackplot(x,y, labels=['Y1','Y2','Y3','Y4'], colors= ["#00b159" , "#ffc425", "#f37735",
plt.legend(loc='upper left')
plt.show()
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 77/79
4/5/2020 Matplotlib
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 78/79
4/5/2020 Matplotlib
END
In [ ]:
localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/Matplotlib.ipynb 79/79