0% found this document useful (0 votes)
13 views79 pages

Data Visualization with Matplotlib

The document discusses various techniques for creating line graphs using Matplotlib in Python. It includes examples of: 1) Creating simple line graphs by plotting x and y data 2) Customizing line styles, colors, and markers 3) Plotting multiple data series on the same graph and adding legends 4) Changing properties like the line width, shading regions, and legend position The goal is to demonstrate the basics of plotting and customizing simple line graphs with Matplotlib.

Uploaded by

RR
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views79 pages

Data Visualization with Matplotlib

The document discusses various techniques for creating line graphs using Matplotlib in Python. It includes examples of: 1) Creating simple line graphs by plotting x and y data 2) Customizing line styles, colors, and markers 3) Plotting multiple data series on the same graph and adding legends 4) Changing properties like the line width, shading regions, and legend position The goal is to demonstrate the basics of plotting and customizing simple line graphs with Matplotlib.

Uploaded by

RR
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

4/5/2020 Matplotlib

Prepared by Asif Bhat

Data Visualization With Python (Matplotlib - Part 1)

In [74]:

import numpy as np
import pandas as pd
import matplotlib as mpl
import [Link] as plt
%matplotlib inline

In [75]:

#Graph Styling
# [Link]
[Link]('seaborn-darkgrid')

Line Graphs

In [76]:

# By default Plot() function will draw a line chart.


x = [Link]([1,2,3,4,5,6])
y = [Link](x,3)
[Link](x,y)
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 1/79
4/5/2020 Matplotlib

In [77]:

x = [Link](0, 10, 1000)


y = [Link](x) # Sine Graph
[Link](x,y)
[Link]()

In [78]:

# Recover default matplotlib settings


[Link]([Link])

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 2/79
4/5/2020 Matplotlib

In [79]:

x = [Link](0, 10, 1000)


y = [Link](x) # Sine Graph
[Link](x,y)
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 3/79
4/5/2020 Matplotlib

In [80]:

[Link]('seaborn-darkgrid')
%matplotlib inline

In [81]:

[Link](figsize=(10,5))
x = [Link](0, 10, 1000)
y = [Link](x) # Sine Graph
[Link](x,y)
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 4/79
4/5/2020 Matplotlib

In [82]:

# Solid blue line will be plotted using the argument "b-"


[Link](figsize=(10,5))
x = [Link](0, 10, 1000)
y = [Link](x) # Sine Graph
[Link](x,y,'b-')
[Link]("X - Axis")
[Link]("Y - Axis")
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 5/79
4/5/2020 Matplotlib

In [83]:

# Solid red line will be plotted using the argument "r-"


[Link](figsize=(10,5))
x = [Link](0, 10, 1000)
y = [Link](x) # Sine Graph
[Link](x,y,'r-')
[Link]("X - Axis")
[Link]("Y - Axis")
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 6/79
4/5/2020 Matplotlib

In [84]:

# Plot green dots using the argument "go"


[Link](figsize=(10,5))
x = [Link](0, 10, 40)
y = [Link](x) # Sine Graph
[Link](x,y,'go')
[Link]("X - Axis")
[Link]("Y - Axis")
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 7/79
4/5/2020 Matplotlib

In [85]:

# Plotting red dots using the argument "ro"


[Link](figsize=(10,5))
x = [Link](0, 10, 40)
y = [Link](x) # Sine Graph
[Link](x,y,'ro')
[Link]("X - Axis")
[Link]("Y - Axis")
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 8/79
4/5/2020 Matplotlib

In [86]:

# Plotting traingular dots using the argument "r^"


[Link](figsize=(10,5))
x = [Link](0, 10, 40)
y = [Link](x) # Sine Graph
[Link](x,y,'r^')
[Link]("X - Axis")
[Link]("Y - Axis")
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 9/79
4/5/2020 Matplotlib

In [115]:

# Plotting traingular dots using the argument "rv"


[Link](figsize=(10,5))
x = [Link](0, 10, 40)
y = [Link](x) # Sine Graph
[Link](x,y,'rv')
[Link]("X - Axis")
[Link]("Y - Axis")
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 10/79
4/5/2020 Matplotlib

In [88]:

#Plotting multiple sets of data


[Link](figsize=(10,5))
x = [Link]([1,2,3,4,5,6])
y1 = [Link](x,2)
y2 = [Link](x,3)
[Link](x,y1, "b-" , label = '$y1 = x^2$') # Setting up legends
[Link](x,y2, "r-" ,label ='$y2 = x^3$') # Setting up legends
[Link]("X - Axis")
[Link]("Y - Axis")
[Link]()
plt.tight_layout()
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 11/79
4/5/2020 Matplotlib

In [116]:

#Plotting multiple sets of data


x = [Link](0, 10, 2000)
[Link](figsize=(10,6))
[Link](x,[Link](x) , label = '$Sin(X)$')
[Link](x,[Link](x) , label = '$cos(X)$')
[Link](r'$X$' , fontsize = 18)
[Link](r'$Y$' , fontsize = 18)
[Link]("$Sin(x) $ $ & $ $ Cos(x)$" ,fontsize = 14)
[Link](loc = 'upper right') # Legend will be placed at upper right position
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 12/79
4/5/2020 Matplotlib

In [117]:

#Changing the line style


[Link](figsize=(10,5))
x = [Link]([1,2,3,4,5,6])
y1 = [Link](x,2)
y2 = [Link](x,3)
[Link](x,y1, "b-" , label = '$y1 = x^2$') # Setting up legends
[Link](x, y2,color='red',linewidth=1.0,linestyle='--') # Setting up legends
[Link]("X - Axis")
[Link]("Y - Axis")
[Link](loc='upper center', fontsize='large')
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 13/79
4/5/2020 Matplotlib

In [118]:

# Line Styling
x = [Link](0, 10, 2000)
[Link](figsize=(16, 9))
[Link](x,[Link](x) , label = '$Sin(X) $ $ Dashed $' , linestyle='dashed')
[Link](x+1,[Link](x) , label = '$Sin(X) $ $ Dashdot $' , linestyle='dashdot')
[Link](x,[Link](x) , label = '$cos(X) $ $ Solid $' , linestyle='solid')
[Link](x+1,[Link](x) , label = '$cos(X)$ $ Dotted $' , linestyle='dotted')
[Link](r'$X$' , fontsize = 18)
[Link](r'$Y$' , fontsize = 18)
[Link]("$Sin(x) $ $ & $ $ Cos(x)$" ,fontsize = 14)
[Link](loc = 'upper right' , fontsize = 14 , bbox_to_anchor=(1.2, 1.0)) # Legend will b
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 14/79
4/5/2020 Matplotlib

In [119]:

# Line Styling
x = [Link](0, 10, 2000)
[Link](figsize=(16, 9))
[Link](x,[Link](x) , label = '$Sin(X) $ $ Dashed $' , linestyle='--')
[Link](x+1,[Link](x) , label = '$Sin(X) $ $ Dashdot $' , linestyle='-.')
[Link](x,[Link](x) , label = '$cos(X) $ $ Solid $' , linestyle='-')
[Link](x+1,[Link](x) , label = '$cos(X)$ $ Dotted $' , linestyle=':')
[Link](r'$X$' , fontsize = 18)
[Link](r'$Y$' , fontsize = 18)
[Link]("$Sin(x) $ $ & $ $ Cos(x)$" ,fontsize = 14)
[Link](loc = 'upper right' , fontsize = 14 , bbox_to_anchor=(1.2, 1.0)) # Legend will b
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 15/79
4/5/2020 Matplotlib

In [93]:

# Shading Regions with fill_between() function


x = [Link](0, 10, 2000)
[Link](figsize=(10,6))
[Link](x,[Link](x) , label = '$Sin(X)$')
[Link](x,[Link](x) , label = '$cos(X)$')
plt.fill_between(x,0,[Link](x))
plt.fill_between(x,0,[Link](x))
[Link](r'$X$' , fontsize = 18)
[Link](r'$Y$' , fontsize = 18)
[Link]("$Sin(x) $ $ & $ $ Cos(x)$" ,fontsize = 14)
[Link](loc = 'lower left') # Legend will be placed at lower left position
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 16/79
4/5/2020 Matplotlib

In [94]:

#Changing Legend position & font


x = [Link]([1,2,3,4,5,6])
y1 = [Link](x,2)
y2 = [Link](x,3)
[Link](x,y1, "b-" , label = '$y1 = x^2$') # Setting up legends
[Link](x,y2, "r-" ,label ='$y2 = x^3$') # Setting up legends
[Link]("X - Axis")
[Link]("Y - Axis")
[Link](loc='upper center', fontsize='large')
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 17/79
4/5/2020 Matplotlib

In [95]:

# Changing line width


[Link](figsize=(10,6))
x= [1,2,3,4,5,6,7,8,9]
y= [7,8,9,10,7,11,12,13,14]
y2 = [7,7,7,7,7,7,7,7,7]
[Link](x , y, linewidth = 4 ,label = 'Line -1') # Changing line width
[Link](x , y2, linewidth = 3,label = 'Line - 2')
[Link]('X Axis Label')
[Link]('Y Axis Label')
[Link] ('Line Graph')
[Link]()
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 18/79
4/5/2020 Matplotlib

In [96]:

# Plot with Grid Lines


[Link](figsize=(10,6))
x= [1,2,3,4,5,6,7,8,9]
y= [7,8,9,10,7,11,12,13,14]
y2 = [7,7,7,7,7,7,7,7,7]
[Link](x , y, linewidth = 4 ,label = 'Line -1') # Changing line width
[Link](x , y2, linewidth = 3,label = 'Line - 2')
[Link]('X Axis Label')
[Link]('Y Axis Label')
[Link] ('Line Graph')
[Link]()
[Link](b=True , linestyle = '-' , which = 'major' , color = 'grey') # Grid Lines
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 19/79
4/5/2020 Matplotlib

In [97]:

# Setting the background color


x = [Link]([1,2,3,4,5,6])
y1 = [Link](x,2)
y2 = [Link](x,3)
[Link](figsize=(12,5)) # Setting the figure size
ax = [Link]()
ax.set_facecolor("darkgrey") # Setting the background color by using Hex code
[Link](x,y1,"bo-", x,y2, "ro-")
[Link]("X - Axis")
[Link]("Y - Axis")
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 20/79
4/5/2020 Matplotlib

In [110]:

# Display multiple plots in one figure (1 row & 2 columns)


[Link](figsize=(14,6))
x = [Link](0, 10, 100)
y1 = [Link](x) # Sine Graph
y2 = [Link](x) # cosine graph
[Link](1,2,1)
[Link](x,y1)
[Link](1,2,2)
[Link](x,y2)
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 21/79
4/5/2020 Matplotlib

In [112]:

# Display multiple plots in one figure (2 row & 1 columns)

[Link](figsize=(12,6))
x = [Link](0, 10, 100)
y1 = [Link](x) # Sine Graph
y2 = [Link](x) # cosine graph

[Link](2,1,1)
[Link](x,y1, "b-")

[Link](2,1,2)
[Link](x,y2, "r-")
plt.tight_layout()
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 22/79
4/5/2020 Matplotlib

In [113]:

# # Display multiple plots in one figure using subplots()


x = [Link](-50,50)
y1 = [Link](x,2)
y2 = [Link](x,3)
y3 = [Link](x)
y4 = [Link](x)
y5 = [Link](x)
y6 = [Link](x)
y7 = [Link](x)
y8 = [Link](x)
y9 = [Link](x)

fig1 , ax1 = [Link](nrows=3,ncols=3 , figsize = (20,20)) # Create a figure and subplo


ax1[0,0].plot(x,y1,"tab:blue") # set the color of the line chart
ax1[0,0].set_title("Square Function") # setting title of subplot
ax1[0,0].set_xlabel(r'$X$' , fontsize = 18) #Set the label for the x-axis
ax1[0,0].set_ylabel(r'$Y$' , fontsize = 18) #Set the label for the y-axis

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/[Link] 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)

[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 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
[Link](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))
[Link](x1,i)
[Link]()

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/[Link] 25/79
4/5/2020 Matplotlib

In [288]:

id1 = [Link](1,10)
score = [Link](20,110,10)
[Link](id1,score)
[Link]('Student ID')
[Link]('Score')
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 26/79
4/5/2020 Matplotlib

In [289]:

id1 = [Link](1,10)
score = [Link](20,110,10)
[Link](figsize=(8,5)) # Setting the figure size
ax = [Link]()
ax.set_facecolor("#ECF0F1") # Setting the background color by specifying the HEX Code
[Link](id1,score,color = '#FFA726')
[Link](r'$Student $ $ ID$')
[Link](r'$Score$')
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 27/79
4/5/2020 Matplotlib

In [290]:

#Plotting multiple sets of data


x1= [1,3,5,7]
x2=[2,4,6,8]
y1 = [7,7,7,7]
y2= [17,18,29,40]
[Link](figsize=(8,6))
ax = [Link]()
ax.set_facecolor("white")
[Link](x1,y1,label = "First",color = '#42B300') # First set of data
[Link](x2,y2,label = "Second",color = '#94E413') # Second set of data
[Link]('$X$')
[Link]('$Y$')
[Link] ('$Bar $ $ Chart$')
[Link]()
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 28/79
4/5/2020 Matplotlib

In [291]:

# Horizontal Bar Chart


Age = [28,33,43,45,57]
Name = ["Asif", "Steve", 'John', "Ravi", "Basit"]
[Link](Name,Age, color ="yellowgreen")
[Link]()

In [293]:

# Changing the width of Bars


num1 = [Link]([1,3,5,7,9])
num2 = [Link]([2,4,6,8,10])
[Link](figsize=(8,4))
[Link](num1, num1**2, width=0.2 , color = '#FF6F00')
[Link](num2, num2**2, width=0.2 , color = '#FFB300')
[Link]()

Out[293]:

[]

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 29/79
4/5/2020 Matplotlib

In [294]:

# Displaying values at the top of vertical bars


num1 = [Link]([1,3,5,7,9])
num2 = [Link]([2,4,6,8,10])
[Link](figsize=(10,6))
[Link](num1, num1**2, width=0.3 , color = '#FF6F00')
[Link](num2, num2**2, width=0.3 , color = '#FFB300')
for x,y in zip(num1,num1**2):
[Link](x, y+0.05, '%d' % y, ha='center' , va= 'bottom')
for x,y in zip(num2,num2**2):
[Link](x, y+0.05, '%d' % y, ha='center' , va= 'bottom')
[Link]()

Out[294]:

[]

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 30/79
4/5/2020 Matplotlib

In [295]:

x = [Link](1,21)
[Link](figsize=(16,8))
y1 = [Link](0.1,0.7,20)
y2 = [Link](0.1,0.7,20)

[Link](x, +y1, facecolor='#C0CA33', edgecolor='white') #specify edgecolor by name


[Link](x, -y2, facecolor='#FF9800', edgecolor='white')

for x,y in zip(x,y1):


[Link](x, y+0.05, '%.2f' % y, ha='center' , va= 'bottom', fontsize = 10)

[Link](0,21)
[Link](-1.25,+1.25)
[Link]()

Stacked Vertical Bar

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 31/79
4/5/2020 Matplotlib

In [296]:

[Link]('seaborn-darkgrid')
x1= ['Asif','Basit','Ravi','Minil']
y1= [17,18,29,40]
y2 = [20,21,22,23]
[Link](figsize=(5,7))
[Link](x1,y1,label = "Open Tickets",width = 0.5,color = '#FF6F00')
[Link](x1,y2,label = "Closed Tickets",width = 0.5 ,bottom = y1 , color = '#FFB300')
[Link]('$X$')
[Link]('$Y$')
[Link] ('$Bar $ $ Chart$')
[Link]()
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 32/79
4/5/2020 Matplotlib

In [297]:

[Link]('seaborn-darkgrid')
x1= ['Asif','Basit','Ravi','Minil']
y1= [Link]([17,18,29,40])
y2 =[Link]([20,21,22,23])
y3 =[Link]([5,9,11,12])
[Link](figsize=(5,7))
[Link](x1,y1,label = "Open Tickets",width = 0.5,color = '#FF6F00')
[Link](x1,y2,label = "Closed Tickets",width = 0.5 ,bottom = y1 , color = '#FFB300')
[Link](x1,y3,label = "Cancelled Tickets",width = 0.5 ,bottom = y1+y2 , color = '#F7DC6F')
[Link]('$X$')
[Link]('$Y$')
[Link] ('$Bar $ $ Chart$')
[Link]()
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 33/79
4/5/2020 Matplotlib

Grouped Bar Chart

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 34/79
4/5/2020 Matplotlib

In [298]:

# Grouped Bar Chart

[Link](figsize=(7,9))

# set width of bar


barWidth = 0.25

# set height of bar


y1= [Link]([17,18,29,40])
y2 =[Link]([20,21,22,23])
y3 =[Link]([5,9,11,12])

# Set position of bar on X axis


pos1 = [Link](len(y1))
pos2 = [x + barWidth for x in pos1]
pos3 = [x + barWidth for x in pos2]

# Make the plot


[Link](pos1, y1, color='#FBC02D', width=barWidth, label='Open')
[Link](pos2, y2, color='#F57F17', width=barWidth, label='Closed')
[Link](pos3, y3, color='#E65100', width=barWidth, label='Cancelled')

# Add xticks on the middle of the group bars


[Link]('Assignee', fontweight='bold')
[Link]('Number of Tickets', fontweight='bold')
[Link]([i + barWidth for i in range(len(y1))], ['Asif', 'Basit', 'Ravi', 'Minil'])

# Create legend & Show graphic


[Link]()
[Link]()
[Link](len(y1))

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 35/79
4/5/2020 Matplotlib

Out[298]:

array([0, 1, 2, 3])

Stacked Vertical Bar

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 36/79
4/5/2020 Matplotlib

In [299]:

[Link]('seaborn-darkgrid')
x1= ['Asif','Basit','Ravi','Minil']
y1= [17,18,29,40]
y2 = [20,21,22,23]
[Link](figsize=(8,5))
[Link](x1,y1,label = "Open Tickets",color = '#FF6F00')
[Link](x1,y2,label = "Closed Tickets", left = y1 , color = '#FFB300')
[Link]('$X$')
[Link]('$Y$')
[Link] ('$Bar $ $ Chart$')
[Link]()
[Link]()

Displaying values in Bar Charts

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 37/79
4/5/2020 Matplotlib

In [300]:

# Displaying values in the stacked vertical bars using [Link]()


[Link]('seaborn-darkgrid')
x1= ['Asif','Basit','Ravi','Minil']
y1= [17,18,29,40]
y2 = [20,21,22,23]
[Link](figsize=(5,7))
[Link](x1,y1,label = "Open Tickets",width = 0.5,color = '#FF6F00')
[Link](x1,y2,label = "Closed Tickets",width = 0.5 ,bottom = y1 , color = '#FFB300')
[Link]('$X$')
[Link]('$Y$')
[Link] ('$Bar $ $ Chart$')
for x,y in zip(x1,y1):
[Link](x, y-10, '%d' % y, ha='center' , va= 'bottom')

for x,y,z in zip(x1,y2,y1):


[Link](x, y+z-10, '%d' % y, ha='center' , va= 'bottom')

[Link]()
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 38/79
4/5/2020 Matplotlib

In [301]:

# Displaying values in the stacked horizontal bars using [Link]()


[Link]('seaborn-darkgrid')
x1= ['Asif','Basit','Ravi','Minil']
y1= [17,18,29,40]
y2 = [20,21,22,23]
[Link](figsize=(8,5))
[Link](x1,y1,label = "Open Tickets",color = '#FF6F00')
[Link](x1,y2,label = "Closed Tickets", left = y1 , color = '#FFB300')
[Link]('$X$')
[Link]('$Y$')

for x,y in zip(x1,y1):


[Link](y-10, x, '%d' % y, ha='center' , va= 'bottom')

for x,y,z in zip(x1,y2,y1):


[Link](y+z-10, x, '%d' % y, ha='center' , va= 'bottom')

[Link] ('$Bar $ $ Chart$')


[Link]()
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 39/79
4/5/2020 Matplotlib

In [302]:

# Displaying values at the top of the Grouped Bar Chart using [Link]()
[Link](figsize=(7,9))

# set width of bar


barWidth = 0.25

# set height of bar


y1= [Link]([17,18,29,40])
y2 =[Link]([20,21,22,23])
y3 =[Link]([5,9,11,12])

# Set position of bar on X axis


pos1 = [Link](len(y1))
pos2 = [x + barWidth for x in pos1]
pos3 = [x + barWidth for x in pos2]

# Make the plot


[Link](pos1, y1, color='#FBC02D', width=barWidth, label='Open')
[Link](pos2, y2, color='#F57F17', width=barWidth, label='Closed')
[Link](pos3, y3, color='#E65100', width=barWidth, label='Cancelled')

# Add xticks on the middle of the group bars


[Link]('Assignee', fontweight='bold')
[Link]('Number of Tickets', fontweight='bold')
[Link]([i + barWidth for i in range(len(y1))], ['Asif', 'Basit', 'Ravi', 'Minil'])

for x,y in zip(pos1,y1):


[Link](x, y, '%d' % y, ha='center' , va= 'bottom')

for x,y in zip(pos2,y2):


[Link](x, y, '%d' % y, ha='center' , va= 'bottom')

for x,y in zip(pos3,y3):


[Link](x, y, '%d' % y, ha='center' , va= 'bottom')

[Link] ('$Grouped $ $ Bar $ $ Chart$')

# Create legend & Show graphic


[Link]()
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 40/79
4/5/2020 Matplotlib

Scatter Graphs

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 41/79
4/5/2020 Matplotlib

In [303]:

x1 = [Link]([250,150,350,252,450,550,455,358,158,355])
y1 =[Link]([40,50,80, 90, 100,50,60,88,54,45])

x2 = [Link]([200,100,300,220,400,500,450,380,180,350])
y2 = [Link]([400,500,800, 900, 1000,500,600,808,504,405])

#Graph - 1
[Link](x1,y1)
[Link]('$Time $ $ Spent$' , fontsize = 12)
[Link]('$Score$' , fontsize = 12)
[Link] ('Scatter Graph')
[Link]()

#Graph - 2
[Link](x2,y2 ,color = 'r')
[Link]('$Time $ $ Spent$' , fontsize = 12)
[Link]('$Score$' , fontsize = 12)
[Link] ('Scatter Graph')
[Link]()

#Graph - 3
[Link](x1,y1 ,label = 'Class 1')
[Link](x2,y2 ,label = 'Class 2',color ='r')
[Link]('$Time $ $ Spent$' , fontsize = 12)
[Link]('$Score$' , fontsize = 12)
[Link] ('Scatter Graph')
[Link]()
[Link]()

#Graph - 4
[Link](x1,y1 ,label = 'Class 1',marker='o' , color = 'm')
[Link](x2,y2 ,label = 'Class 2',marker='v',color ='r')
[Link]('$Time $ $ Spent$' , fontsize = 12)
[Link]('$Score$' , fontsize = 12)
[Link] ('Scatter Graph')
[Link]()
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 42/79
4/5/2020 Matplotlib

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 43/79
4/5/2020 Matplotlib

In [304]:

[Link](figsize=(10,6))
x = [Link](0,10,1000)
y = [Link](0,10,1000)
[Link](x,y)
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 44/79
4/5/2020 Matplotlib

In [305]:

[Link](figsize=(8,6))
x = [Link](10)
y = [Link](10)
# "alpha" is used for softnening colors
[Link]([Link](10),[Link](10),c='r', s=50 , alpha=0.6 , label = 'On
[Link]([Link](10),[Link](10),c='b', s=100 , alpha=0.6 , label = 'T
[Link]([Link](10),[Link](10),c='g', s=150 , alpha=0.6 , label = 'T
[Link]([Link](10),[Link](10),c='y', s=200 , alpha=0.6 , label = 'F
[Link](bbox_to_anchor=(1.0, 1.0) , shadow=True, fontsize='x-large')
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 45/79
4/5/2020 Matplotlib

In [306]:

# Changing label color


[Link](figsize=(8,6))
x = [Link](10)
y = [Link](10)
# "alpha" is used for softnening colors
[Link]['[Link]'] = 'red' # Label Color
[Link]([Link](10),[Link](10),c='r', s=50 , alpha=0.6 , label = 'On
[Link]([Link](10),[Link](10),c='b', s=100 , alpha=0.6 , label = 'T
[Link]([Link](10),[Link](10),c='g', s=150 , alpha=0.6 , label = 'T
[Link]([Link](10),[Link](10),c='y', s=200 , alpha=0.6 , label = 'F
[Link](bbox_to_anchor=(1.0, 1.0) , shadow=True, fontsize='x-large')
[Link]()

In [307]:

# Recover default matplotlib settings


[Link]([Link])
%matplotlib inline
[Link]('seaborn-darkgrid')

Pie Charts

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 46/79
4/5/2020 Matplotlib

In [308]:

[Link](figsize=(9,9))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
[Link] (area , labels= labels , colors= colors , startangle=45)
[Link]()

Display percentage and actual value in Pie Chart

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 47/79
4/5/2020 Matplotlib

In [309]:

# Display percentage in Pie Chart using autopct='%1.1f%%'


[Link](figsize=(8,8))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#7CB342','#C0CA33','#FFB300','#F57C00']
[Link] (area , labels= labels , colors= colors , startangle=45 , shadow='true', autopct='%
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 48/79
4/5/2020 Matplotlib

In [310]:

[Link](figsize=(8,8))
area = [48 , 30 , 20 , 15]
total = [Link](area)
labels = ['Low' , 'Medium' , 'High' , 'Critical']

def val_per(x):
return '{:.2f}%\n({:.0f})'.format(x, total*x/100)

colors = ['#7CB342','#C0CA33','#FFB300','#F57C00']
[Link] (area , labels= labels , colors= colors , startangle=45 , shadow='true', autopct=va
[Link]()

Explode Slice in Pie Chart

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 49/79
4/5/2020 Matplotlib

In [311]:

#Explode 4th Slice


[Link](figsize=(8,8))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#7CB342','#C0CA33','#FFB300','#F57C00']
# explode = [0,0,0,0.1] will explode the fourth slice
[Link] (area , labels= labels , colors= colors , startangle=45 , autopct='%1.1f%%' , shado
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 50/79
4/5/2020 Matplotlib

In [312]:

#Explode 3rd & 4th Slice


[Link](figsize=(8,8))
area = [48 , 30 , 20 , 15]
label = ['Low' , 'Medium' , 'High' , 'Critical']
color = ['#7CB342','#C0CA33','#FFB300','#F57C00']
# explode = [0,0,0.1,0.1] will explode the 3rd & 4th slice
[Link] (area , labels= label , colors= color , startangle=45 ,autopct='%1.1f%%', shadow='t
[Link]()
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 51/79
4/5/2020 Matplotlib

Donut plot

In [313]:

[Link](figsize=(9,9))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
[Link] (area , labels= labels , colors= colors , startangle=45)
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 52/79
4/5/2020 Matplotlib

In [314]:

# Changing background color


fig = [Link](figsize=(9,9))
[Link].set_facecolor('#DADADA') # Changing background color of donut chart
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
[Link] (area , labels= labels , colors= colors , startangle=45)
my_circle=[Link]( (0,0), 0.7, color='#DADADA') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 53/79
4/5/2020 Matplotlib

Explode Slice in Donut Chart

In [315]:

[Link](figsize=(9,9))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
[Link] (area , labels= labels , colors= colors , startangle=45 , explode=[0,0 , 0.0 , 0.1]
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 54/79
4/5/2020 Matplotlib

In [316]:

[Link](figsize=(9,9))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
[Link] (area , labels= labels , colors= colors , startangle=45 , explode=[0,0 , 0.1 , 0.1]
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 55/79
4/5/2020 Matplotlib

In [317]:

[Link](figsize=(9,9))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
[Link] (area , labels= labels , colors= colors , startangle=45 , explode=[0.03,0.03 , 0.03
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)
[Link]()

Displaying percentage and actual values in Donut Chart

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 56/79
4/5/2020 Matplotlib

In [318]:

[Link](figsize=(9,9))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
[Link] (area , labels= labels , colors= colors , startangle=45 , autopct='%1.1f%%', explod
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 57/79
4/5/2020 Matplotlib

In [319]:

[Link](figsize=(9,9))
area = [48 , 30 , 20 , 15]
labels = ['Low' , 'Medium' , 'High' , 'Critical']
colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
[Link] (area , labels= labels , colors= colors , startangle=45 , autopct='%1.1f%%', pctdis
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 58/79
4/5/2020 Matplotlib

In [320]:

[Link](figsize=(9,9))
area = [48 , 30 , 20 , 15]
total = [Link](area)

def val_per(x):
return '{:.2f}%\n({:.0f})'.format(x, total*x/100)

labels = ['Low' , 'Medium' , 'High' , 'Critical']


colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']
[Link] (area , labels= labels , colors= colors , startangle=45 , autopct=val_per, pctdista
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 59/79
4/5/2020 Matplotlib

Display multiple Donut plots in one figure

In [321]:

fig = [Link](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']

[Link](1,3,1)
[Link] (area , labels= priority , colors= colors , startangle=45)
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)

[Link](1,3,2)
[Link] (area , labels= status , colors= colors , startangle=45)
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)

[Link](1,3,3)
[Link] (area , labels= company , colors= colors , startangle=45)
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)

[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 60/79
4/5/2020 Matplotlib

In [322]:

fig = [Link](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']

[Link](2,3,1)
[Link] (area , labels= priority , colors= colors , startangle=45)
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)

[Link](2,3,2)
[Link] (area , labels= status , colors= colors , startangle=45)
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)

[Link](2,3,3)
[Link] (area , labels= company , colors= colors , startangle=45)
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)

[Link](2,3,4)
[Link] (area , labels= priority , colors= colors , startangle=45)
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)

[Link](2,3,5)
[Link] (area , labels= status , colors= colors , startangle=45)
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)

[Link](2,3,6)
[Link] (area , labels= company , colors= colors , startangle=45)
my_circle=[Link]( (0,0), 0.7, color='white') # Adding circle at the centre
p=[Link]()
[Link]().add_artist(my_circle)

[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 61/79
4/5/2020 Matplotlib

Histogram

In [323]:

x = [Link](size = 2000)
[Link](x, bins=40, color='yellowgreen')
[Link]().set(title='Histogram', ylabel='Frequency')
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 62/79
4/5/2020 Matplotlib

In [324]:

x = [Link](2000)
[Link](x, bins=30 ,color='#D4AC0D')
[Link]().set(title='Histogram', ylabel='Frequency')
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 63/79
4/5/2020 Matplotlib

In [325]:

# Using Edge Color for readability


[Link](figsize=(10,8))
x = [Link](size = 2000)
[Link](x, bins=40, color='yellowgreen' , edgecolor="#6A9662")
[Link]().set(title='Histogram', ylabel='Frequency')
[Link]()

Binning

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 64/79
4/5/2020 Matplotlib

In [326]:

# Binning
[Link](figsize=(10,8))
x = [Link](size = 2000)
[Link](x, bins=30, color='yellowgreen' , edgecolor="#6A9662")
[Link]().set(title='Histogram', ylabel='Frequency')
[Link]()

[Link](figsize=(10,8))
[Link](x, bins=20, color='yellowgreen' , edgecolor="#6A9662")
[Link]().set(title='Histogram', ylabel='Frequency')
[Link]()

[Link](figsize=(10,8))
[Link](x, bins=10, color='yellowgreen' , edgecolor="#6A9662")
[Link]().set(title='Histogram', ylabel='Frequency')
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 65/79
4/5/2020 Matplotlib

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 66/79
4/5/2020 Matplotlib

Plotting Multiple Histograms

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 67/79
4/5/2020 Matplotlib

In [329]:

[Link](figsize=(8,11))
x = [Link](-4,1,size = 800)
y = [Link](0,1.5,size = 800)
z = [Link](3.5,1,size = 800)
[Link](x, bins=30, color='yellowgreen' , alpha=0.6)
[Link](y, bins=30, color='#FF8F00' , alpha=0.6)
[Link](z, bins=30, color='blue' , alpha=0.6)
[Link]().set(title='Histogram', ylabel='Frequency')
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 68/79
4/5/2020 Matplotlib

In [330]:

# Using Histogram to plot a cumulative distribution function


[Link](figsize=(10,8))
x = [Link](2000)
[Link](x, bins=30 ,color='#ffa41b' , edgecolor="#639a67",cumulative=True)
[Link]().set(title='Histogram', ylabel='Frequency')
[Link]()

Area Plot

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 69/79
4/5/2020 Matplotlib

In [331]:

x = [Link](1,31)
y = [Link](10,11,size=30)
y = [Link](y)
[Link](figsize=(16,6))
[Link](x,y)
plt.fill_between(x, y)
[Link]()

Changing Fill Color

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 70/79
4/5/2020 Matplotlib

In [334]:

x = [Link](1,31)
y = [Link](10,11,size=30)
y = [Link](y)
[Link](figsize=(16,6))

plt.fill_between( x, y, color="#baf1a1") # #Changing Fill color


[Link](x, y, color='#7fcd91') # Color on edges

[Link]("$ Area $ $ chart $" , fontsize = 16)


[Link]("$X$" , fontsize = 16)
[Link]("$Y$" , fontsize = 16)

[Link]()

Changing Fill Color and its transperancy

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 71/79
4/5/2020 Matplotlib

In [336]:

x = [Link](1,31)
y = [Link](10,11,size=30)
y = [Link](y)
[Link](figsize=(16,6))

plt.fill_between( x, y, color="#C8D700" , alpha = 0.3) # Changing transperancy using Alpha


[Link](x, y, color='#36BD00')

[Link]("$ Area $ $ chart $" , fontsize = 16)


[Link]("$X$" , fontsize = 16)
[Link]("$Y$" , fontsize = 16)

[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 72/79
4/5/2020 Matplotlib

In [338]:

x = [Link](1,51)
y = [Link](1,5,size=50)
y = [Link](y)

[Link](figsize=(16,6))
plt.fill_between( x, y, color="#5ac8fa", alpha=0.4)
[Link](x, y, color="blue", alpha=0.6) # Bold line on edges
[Link]("$ Area $ $ chart $" , fontsize = 16)
[Link]("$X$" , fontsize = 16)
[Link]("$Y$" , fontsize = 16)
[Link]()

[Link](figsize=(16,6))
plt.fill_between( x, y, color="#5ac8fa", alpha=0.4)
[Link](x, y, color="blue", alpha=0.2) # Less stronger line on edges
[Link]("$ Area $ $ chart $" , fontsize = 14)
[Link]("$X$" , fontsize = 14)
[Link]("$Y$" , fontsize = 14)
[Link]()

Stacked Area plot

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 73/79
4/5/2020 Matplotlib

In [339]:

x=[Link](1,6)
y1 = [Link]([1,5,9,13,17])
y2 = [Link]([2,6,10,14,16])
y3 = [Link]([3,7,11,15,19])
y4 = [Link]([4,8,12,16,20])

[Link](figsize=(8,6))
[Link](x,y1,y2,y3,y4, labels=['Y1','Y2','Y3','Y4'])
[Link](loc='upper left')
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 74/79
4/5/2020 Matplotlib

In [340]:

x=[Link](1,6)
y=[ [1,5,9,13,17], [2,6,10,14,16], [3,7,11,15,19] , [4,8,12,16,20] ]
[Link](figsize=(8,6))
[Link](x,y , labels=['Y1','Y2','Y3','Y4'])
[Link](loc='upper left')
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 75/79
4/5/2020 Matplotlib

In [341]:

x=[Link](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] ]
[Link](figsize=(10,6))
[Link](x,y , labels=['Y1','Y2','Y3','Y4'])
[Link](loc='upper left')
[Link]()

Changing Fill Color and its transperancy in Stacked Plot

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 76/79
4/5/2020 Matplotlib

In [342]:

x=[Link](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] ]

[Link](figsize=(11,6))
[Link](x,y , labels=['Y1','Y2','Y3','Y4'] , colors= ["#00b159" , "#ffc425", "#f37735
[Link](loc='upper left')
[Link]()

[Link](figsize=(11,6))
[Link](x,y, labels=['Y1','Y2','Y3','Y4'], colors= ["#00b159" , "#ffc425", "#f37735",
[Link](loc='upper left')
[Link]()

[Link](figsize=(11,6))
[Link](x,y, labels=['Y1','Y2','Y3','Y4'], colors= ["#00b159" , "#ffc425", "#f37735",
[Link](loc='upper left')
[Link]()

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 77/79
4/5/2020 Matplotlib

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 78/79
4/5/2020 Matplotlib

END

In [ ]:

localhost:8888/notebooks/Documents/GitHub/Public/Data-Visualization/[Link] 79/79

You might also like