<jupyter_start><jupyter_text>**Data Visualization** **Agenda**1.   What is Data Visualization?2.   Why Data Visualization?3.   What is Matplotlib?4.   Types of Plots5.   Getting Started with Matplotlib6.   Adding Styles to Our Graph6.   Introduction to Seaborn7.   Seaborn vs Matplotlib8.   Installing Seaborn9.   Installing Dependencies10.  Plotting Functions11.  Multi-Plot Grids12.  Plot-Aesthetics  **1. What is Data Visualization?**Data visualization is the presentation of data in a pictorial or graphical format.  **2. Why Data Visualization?**Human brain can process information easily when it is graphical or pictorial form.Data visualization allows us to quickly interpret the data and adjust different variables to see their effect.  **3. What is Matplotlib?**Matplotlib is a Python package used for 2D graphics. It's a comprehensive library for creating static, animated, and interactive, visualizations in python. It is easily customizable through accessing the class.See [Matplotlib documentations](https://matplotlib.org/py-modindex.html)  **4. Types of Plots**There are many types of plotting, few of them which are commonly used are visualized below.  **5. Getting Started with Matplotlib**<jupyter_code>#Make sure Matplotlib is installed in your pip environment.
#Installing Matplotlib

!pip install Matplotlib
#Importing pylot function as alias "plt" from Matplotlib library
from matplotlib import pyplot as plt
#Plotting to our canvas
plt.plot([1,2,3],[4,5,9])

#Showing what we plotted
plt.show()
#Lets add title and labels to our graph
x= [10,16,20]
y=[24,32,12]

plt.plot(x,y)

plt.title("Just Playing Around")
plt.ylabel('Y axis')
plt.xlabel('X axis')

plt.show()<jupyter_output><empty_output><jupyter_text>**6. Adding Styles to Our Graph**<jupyter_code>#Importing style function from MatplotLib
from matplotlib import style 

style.use("ggplot")

x= [10,16,20]
y= [24,32,12]

x2= [12,19,24]
y2= [20,28,18] 

plt.plot(x,y,'g', label ='Line 1', linewidth = 4)
plt.plot(x2,y2,'c', label = "Line 2", linewidth=4)

plt.title('Added Style')
plt.ylabel('Y axis')
plt.xlabel('X axis')

plt.legend()

plt.grid(True, color = 'k') # Red = "r", Blue = "b", Green = "g", Black = "k"
plt.show()<jupyter_output><empty_output><jupyter_text>**7. Bar Graph**Bar graphs can be used to show how something changes over time or to compare items. They have an x-axis (horizontal) and a y-axis (vertical).***Bar Graph uses Categorical Data***<jupyter_code>plt.bar([2,4,6,8,10],[10,4,14,16,6]) #Where x = [2,4,6,8,10] & y = [10,4,14,16,6]

plt.xlabel('bar number')
plt.ylabel('bar height')

plt.title("Bar Graph")
plt.show()<jupyter_output><empty_output><jupyter_text>**8. Histogram**A histogram is a graphical display of data using bars of different heights. In a histogram, each bar groups numbers into ranges. Taller bars show that more data falls in that range. A histogram displays the shape and spread of continuous sample data.***Histogram uses Quantative Data***<jupyter_code>x = [21,22,23,4,5,6,77,8,9,10,31,32,33,34,35,36,37,18,49,50,100]
num_bins = 10

plt.hist(x, num_bins)

plt.xlabel("Weekly Earnings ($)")
plt.ylabel("No. of Students")

plt.title("Histogram")

#plt.legend()

plt.show()<jupyter_output><empty_output><jupyter_text>**9. Scatter Plot**A scatter plot uses dots to represent values for two different numeric variables. The position of each dot on the horizontal and vertical axis indicates values for an individual data point. Scatter plots are used to observe relationships between variables.<jupyter_code>x= [2,4,6,8,10,12]
y= [4,8,12,16,20,24]

plt.scatter(x,y, color = 'r')

plt.xlabel('x')
plt.ylabel('y')
plt.title('Scatter Plot')

plt.show()<jupyter_output><empty_output><jupyter_text>**10. Stack Plot**A stack plot is a plot that shows the whole data set with easy visualization of how each part makes up the whole. Each constituent of the stack plot is stacked on top of each other. It shows the part makeup of the unit, as well as the whole unit.<jupyter_code>years = [2000, 2005, 2010, 2015, 2020]

revenue = [140, 250, 300, 400, 500]
profit = [40, 50, 60, 70, 130]

plt.stackplot(years, profit, revenue, colors = ['r','k','b'])

plt.xlabel('Years')
plt.ylabel('Billions ($)')
plt.title('Stack or Area Plot')
plt.show()<jupyter_output><empty_output><jupyter_text>**11. Pie Chart****EveryoneKnowsIt**A pie chart is a circular statistical graphic, which is divided into slices to illustrate numerical proportion. In a pie chart, the arc length of each slice, is proportional to the quantity it represents.<jupyter_code>students = [1000, 1450, 6094, 4150, 2150]
interests = ['XR Development','Game Development','Web Development','Mobile Apps','Artificial Intelligence & Data SCience']
col= ['r','b','g','y','m']

plt.pie(students,labels=interests, colors= col)

plt.title('Pie Plot')

plt.show()<jupyter_output><empty_output><jupyter_text>**12. Introduction to Seaborn**Seaborn is a library for making statistical graphics in Python. It builds on top of matplotlib and integrates closely with pandas data structures.Seaborn helps you explore and understand your data. Its plotting functions operate on dataframes and arrays containing whole datasets and internally perform the necessary semantic mapping and statistical aggregation to produce informative plots. Its dataset-oriented, declarative API lets you focus on what the different elements of your plots mean, rather than on the details of how to draw them.**Matplotlib:** Matplotlib is mainly deployed for basic plotting. Visualization using Matplotlib generally consists of bars, pies, lines, scatter plots and so on.**Seaborn:** Seaborn, on the other hand, provides a variety of visualization patterns. It uses fewer syntax and has easily interesting default themes.See [Seaborn Documentations](https://seaborn.pydata.org/introduction.html)  **13. Getting Started with Seaborn**Seaborn has 4 dependencies. before installing Seaborn, make sure you have already installed NumPy, Pandas, Matplotlib and SciPy<jupyter_code>#Installing dependencies (if haven't)
!pip install pandas
!pip install numpy
!pip install matplotlib 
!pip install scipy

#Installing Seaborn
!pip install seaborn
#Importing all dependencies and Seaborn itself
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import scipy
import seaborn as sns
#Relationship Plot
a = sns.load_dataset("flights")
sns.relplot(x="passengers", y="month", data=a) #Add hue=y and try with different combinations
b = sns.load_dataset("tips")
sns.relplot(x="time", y="tip", data=b, kind ="line")
#Categorical Plot

sns.catplot(x="day", y="total_bill", data=b)<jupyter_output><empty_output><jupyter_text>**For Skewed Data** **Violin Plot**<jupyter_code>sns.catplot(x="day", y="total_bill", kind= "violin", data=b)<jupyter_output><empty_output><jupyter_text>**Box Plot**<jupyter_code>sns.catplot(x="day", y="total_bill",kind="boxen", data=b)<jupyter_output><empty_output><jupyter_text>**14. Multi-Plot Grids**Graphs are plotted side-by-side using the same scale and axes to aid comparisonIt is pretty useful to help developer or researchers to understand the large amount of data in a blink.<jupyter_code>a = sns.load_dataset("iris")
b = sns.FacetGrid(a, col = "species")
b.map(plt.hist, "sepal_length")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1161706213139487, 'fraction_numerical': 0.032780139898505006, 'mean_word_length': 6.0115384615384615, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '63010', 'license': 'MIT', 'n_tokens_mistral': 2553, 'n_tokens_neox': 2306, 'n_words': 817, 'path': '03_Data_Visualization/03_DataVisualization.ipynb', 'repo_name': 'mhuzaifadev/mlzero_to_hero', 'size': '7291'}