SlideShare une entreprise Scribd logo
1  sur  23
Chapter – 4
Data Science with Python
Intro to Data Visualization with Matplotlib
Prof. Maulik Borsaniya
Maulik Borsaniya - Gardividyapith
Data Visualization
 Data visualization is a very important part of data
analysis. You can use it to explore your data. If you
understand your data well, you’ll have a better chance
to find some insights. Finally, when you find any
insights, you can use visualizations again to be able to
share your findings with other people.
 However, the idea here is to learn the fundamentals of
Data Visualization and Matplotlib. So, our plots will be
much simpler than that example.
Maulik Borsaniya - Gardividyapith
Basic Visualization Rules
 Before we look at some kinds of plots, we’ll introduce
some basic rules. Those rules help us make nice and
informative plots instead of confusing ones.
Steps
i. The first step is to choose the appropriate plot type. If there
are various options, we can try to compare them, and
choose the one that fits our model the best.
ii. Second, when we choose your type of plot, one of the most
important things is to label your axis. If we don’t do this,
the plot is not informative enough.
iii. Third, we can add a title to make our plot more informative.
Maulik Borsaniya - Gardividyapith
IV Fourth, add labels for different categories when needed.
V Five, optionally we can add a text or an arrow
at interesting data points.
VI Six, in some cases we can use some sizes and colors of
the data to make the plot more informative.
Maulik Borsaniya - Gardividyapith
What is Matplotlib ?
 Matplotlib is a python library used to create 2D graphs and plots by
using python scripts. It has a module named pyplot which makes
things easy for plotting by providing feature to control line styles, font
properties, formatting axes etc. It supports a very wide variety of
graphs and plots namely - histogram, bar charts, power spectra, error
charts etc.
 It is used along with NumPy to provide an environment that is an effective
open source alternative for MatLab.
 Pyplot is a matplotlib module which provides a MATLAB-like interface.
 Matplotlib is designed to be as usable as MATLAB, with the ability to use
Python, and the advantage of being free and open-source.
Maulik Borsaniya - Gardividyapith
How to install Matplotlib ?
 First of all you need to download Python from python.org .Which must be
Latest version.
 Installing in windows you need to type following command in CMD.
python –mpip install -U pip
python –mpip install -U matplotlib
 For Ubuntu.
sudo apt-get build-dep python-matplotlib
Maulik Borsaniya - Gardividyapith
Simple Example of Plotting(Sine wave form)
import numpy as np
import matplotlib.pyplot as plt
# Compute the x and y coordinates for points on a sine curve
x = np.arange(0, 3 * np.pi, 0.1)
y = np.sin(x)
plt.title("sine wave form")
# Plot the points using matplotlib
plt.plot(x, y)
plt.show()
Maulik Borsaniya - Gardividyapith
Sr.No. Parameter & Description
1 Start
The start of an interval. If omitted, defaults to 0
2 Stop
The end of an interval (not including this number)
3 Step
Spacing between values, default is 1
4 dtype
Data type of resulting ndarray. If not given, data type
of input is used
numpy.arange(start, stop, step, dtype)
The constructor takes the following parameters
Maulik Borsaniya - Gardividyapith
Scatter Plot
 this type of plot shows all individual data points. Here, they aren’t
connected with lines. Each data point has the value of the x-axis
value and the value from the y-axis values. This type of plot can be
used to display trends or correlations.
 In data science, it shows how 2 variables compare.
To make a scatter plot with Matplotlib, we can use
the plt.scatter()function. Again, the first argument is used for the
data on the horizontal axis, and the second - for the vertical axis.
Maulik Borsaniya - Gardividyapith
Example Scatter Plot
import matplotlib.pyplot as plt
temp = [30, 32, 33, 28.5, 35, 29, 29]
ice_creams_count = [100, 115, 115, 75, 125, 79, 89]
plt.scatter(temp, ice_creams_count)
plt.title("Temperature vs. Sold ice creams")
plt.xlabel("Temperature")
plt.ylabel("Sold ice creams count")
plt.show()
Maulik Borsaniya - Gardividyapith
Bar chart
 represents categorical data with rectangular bars. Each bar
has a height corresponds to the value it represents. It’s
useful when we want to compare a given numeric value on
different categories. It can also be used with 2 data series.
 To make a bar chart with Maplotlib, we’ll need
the plt.bar() function.
Maulik Borsaniya - Gardividyapith
E.g.. Bar Chart
# Our data
import matplotlib.pyplot as plt
labels = ["JavaScript", "Java", "Python", "C#"]
usage = [69.8, 45.3, 38.8, 34.4]
# Generating the y positions. Later, we'll use them to replace them with labels.
y_positions = range(len(labels))
# Creating our bar plot
plt.bar(y_positions, usage)
plt.xticks(y_positions, labels)
plt.ylabel("Usage (%)")
plt.title("Programming language usage")
plt.show()
Maulik Borsaniya - Gardividyapith
Pie chart
a circular plot, divided into slices to show numerical proportion.
They are widely used in the business world.
However, many experts recommend to avoid them. The main
reason is that it’s difficult to compare the sections of a given pie
chart. Also, it’s difficult to compare data across multiple pie
charts.
In many cases, they can be replaced by a bar chart.
Maulik Borsaniya - Gardividyapith
Pie Chart Example
import matplotlib.pyplot as plt
sizes = [25, 20, 45, 10]
labels = ["Cats", "Dogs", "Tigers", "Goats"]
plt.pie(sizes, labels = labels, autopct = "%.2f")#float and persentage value
plt.axes().set_aspect("equal")#auto #num #aspect ratio
plt.show()
Maulik Borsaniya - Gardividyapith
Working With Data Science And Panda
 Pandas is an open-source Python Library used for high-
performance data manipulation and data analysis using its
powerful data structures. Python with pandas is in use in a variety
of academic and commercial domains, including Finance,
Economics, Statistics, Advertising, Web Analytics, and more.
 Using Pandas, we can accomplish five typical steps in the
processing and analysis of data, regardless of the origin of data —
load, organize, manipulate, model, and analyze the data.
 Below are the some of the important features of Pandas which is
used specifically for Data processing and Data analysis work.
Maulik Borsaniya - Gardividyapith
If you want to work with data & sheets you need
to do and install Panda First.
Installation steps
In Windows
-> CMD - > Go to the specific python installed directory.
 type following command over there and keep breathing…( )
C:>Python pip install pandas
For Ubuntu
-> Terminal
Type following commands.
>> sudo pip install pandas
Maulik Borsaniya - Gardividyapith
Pandas handles data through Series, Data Frame, and Panel. We will see
some examples from each of these.
Pandas Series
 Series is a one-dimensional labeled array capable of holding data of any type
(integer, string, float, python objects, etc.). The axis labels are collectively called
index. A pandas Series can be created using the following constructor
Syntax : pandas. Series( data, index, dtype, copy)
#import the pandas library and aliasing as pd
import pandas as pd
import numpy as np
data = np.array(['a','b','c','d'])
s = pd.Series(data)
print s
Maulik Borsaniya - Gardividyapith
Pandas Data Frame
 A Data frame is a two-dimensional data structure, i.e., data is
aligned in a tabular fashion in rows and columns. A pandas Data
Frame can be created using the following constructor
 Syntax : pandas.DataFrame( data, index, columns, dtype, copy)
Eg.
import pandas as pd
data = {'Name':['Tom', 'Jack', 'Steve', 'Ricky'],'Age':[28,34,29,42]}
df = pd.DataFrame(data, index=['rank1','rank2','rank3','rank4'])
print df
Maulik Borsaniya - Gardividyapith
What is Data Frame ?
 A Data frame is a two-dimensional data structure, i.e.,
data is aligned in a tabular fashion in rows and columns.
Features of Data Frame
 Potentially columns are of different types
 Size – Mutable
 Labeled axes (rows and columns)
 Can Perform Arithmetic operations on rows and columns
 Structure
Maulik Borsaniya - Gardividyapith
Maulik Borsaniya - Gardividyapith
Data frame from list
import pandas as pd
data = [1,2,3,4,5]
df = pd.DataFrame(data)
print (df)
E.g.2
import pandas as pd
data = [['Alex',10],['Bob',12],['Clarke',13]]
df = pd.DataFrame(data,columns=['Name','Age'])
print df
E.g.3
import pandas as pd
data = [['Alex',10],['Bob',12],['Clarke',13]]
Df=pd.DataFrame(data,columns=['Name','Age'],dtype=float)
print df
Maulik Borsaniya - Gardividyapith
Creating Data Frame from Dictionary
import pandas as pd
data = {'Name':['Tom', 'Jack', 'Steve', 'Ricky'],'Age':[28,34,29,42]}
df = pd.DataFrame(data)
print df
Maulik Borsaniya - Gardividyapith
Reading Data From CSV / Excel
import pandas as pd
data = pd.read_csv('C:Python34/sheet1.csv')
print (data)
Reading Specific Row – Eg.2
import pandas as pd
data = pd.read_csv('C:Python34/sheet1.csv')
# Slice the result for first 5 rows
print (data[0:5]['salary'])
#for Excel you can use read_excel…..
Maulik Borsaniya - Gardividyapith

Contenu connexe

Tendances

Data visualization in Python
Data visualization in PythonData visualization in Python
Data visualization in PythonMarc Garcia
 
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPyDevashish Kumar
 
Data Analysis and Visualization using Python
Data Analysis and Visualization using PythonData Analysis and Visualization using Python
Data Analysis and Visualization using PythonChariza Pladin
 
Introduction to pandas
Introduction to pandasIntroduction to pandas
Introduction to pandasPiyush rai
 
Python Pandas
Python PandasPython Pandas
Python PandasSunil OS
 
pandas - Python Data Analysis
pandas - Python Data Analysispandas - Python Data Analysis
pandas - Python Data AnalysisAndrew Henshaw
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in pythonhydpy
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksEueung Mulyana
 
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Edureka!
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in PythonDevashish Kumar
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaEdureka!
 
Basics of Algorithms.pdf
Basics of Algorithms.pdfBasics of Algorithms.pdf
Basics of Algorithms.pdfKshitijPandey59
 

Tendances (20)

Data visualization in Python
Data visualization in PythonData visualization in Python
Data visualization in Python
 
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPy
 
Data Analysis and Visualization using Python
Data Analysis and Visualization using PythonData Analysis and Visualization using Python
Data Analysis and Visualization using Python
 
Seaborn.pptx
Seaborn.pptxSeaborn.pptx
Seaborn.pptx
 
Introduction to pandas
Introduction to pandasIntroduction to pandas
Introduction to pandas
 
NUMPY
NUMPY NUMPY
NUMPY
 
Pandas
PandasPandas
Pandas
 
Python Pandas
Python PandasPython Pandas
Python Pandas
 
pandas - Python Data Analysis
pandas - Python Data Analysispandas - Python Data Analysis
pandas - Python Data Analysis
 
MatplotLib.pptx
MatplotLib.pptxMatplotLib.pptx
MatplotLib.pptx
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 
Python pandas Library
Python pandas LibraryPython pandas Library
Python pandas Library
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter Notebooks
 
NumPy.pptx
NumPy.pptxNumPy.pptx
NumPy.pptx
 
Data visualization
Data visualizationData visualization
Data visualization
 
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | Edureka
 
Basics of Algorithms.pdf
Basics of Algorithms.pdfBasics of Algorithms.pdf
Basics of Algorithms.pdf
 

Similaire à Data Visualization with Matplotlib in Python

Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxSharmilaMore5
 
Python Pyplot Class XII
Python Pyplot Class XIIPython Pyplot Class XII
Python Pyplot Class XIIajay_opjs
 
Machine Learning with Python-Data Visualization.pdf
Machine Learning with Python-Data Visualization.pdfMachine Learning with Python-Data Visualization.pdf
Machine Learning with Python-Data Visualization.pdfSHIBDASDUTTA
 
Lecture 1 Pandas Basics.pptx machine learning
Lecture 1 Pandas Basics.pptx machine learningLecture 1 Pandas Basics.pptx machine learning
Lecture 1 Pandas Basics.pptx machine learningmy6305874
 
Data visualization using py plot part i
Data visualization using py plot part iData visualization using py plot part i
Data visualization using py plot part iTutorialAICSIP
 
Lesson 2 data preprocessing
Lesson 2   data preprocessingLesson 2   data preprocessing
Lesson 2 data preprocessingAbdurRazzaqe1
 
A Map of the PyData Stack
A Map of the PyData StackA Map of the PyData Stack
A Map of the PyData StackPeadar Coyle
 
PPT on Data Science Using Python
PPT on Data Science Using PythonPPT on Data Science Using Python
PPT on Data Science Using PythonNishantKumar1179
 
Pandas data transformational data structure patterns and challenges final
Pandas   data transformational data structure patterns and challenges  finalPandas   data transformational data structure patterns and challenges  final
Pandas data transformational data structure patterns and challenges finalRajesh M
 
Tutorial machine learning with python - a tutorial
Tutorial   machine learning with python - a tutorialTutorial   machine learning with python - a tutorial
Tutorial machine learning with python - a tutorialMarcusBBraga
 
Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib. Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib. yazad dumasia
 
16. Data VIsualization using PyPlot.pdf
16. Data VIsualization using PyPlot.pdf16. Data VIsualization using PyPlot.pdf
16. Data VIsualization using PyPlot.pdfRrCreations5
 
Analysis using r
Analysis using rAnalysis using r
Analysis using rPriya Mohan
 
Meetup Junio Data Analysis with python 2018
Meetup Junio Data Analysis with python 2018Meetup Junio Data Analysis with python 2018
Meetup Junio Data Analysis with python 2018DataLab Community
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxParveenShaik21
 
Tips and Tricks for Data Visualization in Python
Tips and Tricks for Data Visualization in PythonTips and Tricks for Data Visualization in Python
Tips and Tricks for Data Visualization in PythonJacqueline Carvalho
 

Similaire à Data Visualization with Matplotlib in Python (20)

Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptx
 
More on Pandas.pptx
More on Pandas.pptxMore on Pandas.pptx
More on Pandas.pptx
 
Python Pyplot Class XII
Python Pyplot Class XIIPython Pyplot Class XII
Python Pyplot Class XII
 
12-IP.pdf
12-IP.pdf12-IP.pdf
12-IP.pdf
 
Machine Learning with Python-Data Visualization.pdf
Machine Learning with Python-Data Visualization.pdfMachine Learning with Python-Data Visualization.pdf
Machine Learning with Python-Data Visualization.pdf
 
Lecture 1 Pandas Basics.pptx machine learning
Lecture 1 Pandas Basics.pptx machine learningLecture 1 Pandas Basics.pptx machine learning
Lecture 1 Pandas Basics.pptx machine learning
 
Data visualization using py plot part i
Data visualization using py plot part iData visualization using py plot part i
Data visualization using py plot part i
 
Lesson 2 data preprocessing
Lesson 2   data preprocessingLesson 2   data preprocessing
Lesson 2 data preprocessing
 
A Map of the PyData Stack
A Map of the PyData StackA Map of the PyData Stack
A Map of the PyData Stack
 
BDACA - Tutorial5
BDACA - Tutorial5BDACA - Tutorial5
BDACA - Tutorial5
 
PPT on Data Science Using Python
PPT on Data Science Using PythonPPT on Data Science Using Python
PPT on Data Science Using Python
 
Pandas data transformational data structure patterns and challenges final
Pandas   data transformational data structure patterns and challenges  finalPandas   data transformational data structure patterns and challenges  final
Pandas data transformational data structure patterns and challenges final
 
Tutorial machine learning with python - a tutorial
Tutorial   machine learning with python - a tutorialTutorial   machine learning with python - a tutorial
Tutorial machine learning with python - a tutorial
 
Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib. Introduction to Pylab and Matploitlib.
Introduction to Pylab and Matploitlib.
 
16. Data VIsualization using PyPlot.pdf
16. Data VIsualization using PyPlot.pdf16. Data VIsualization using PyPlot.pdf
16. Data VIsualization using PyPlot.pdf
 
Analysis using r
Analysis using rAnalysis using r
Analysis using r
 
Meetup Junio Data Analysis with python 2018
Meetup Junio Data Analysis with python 2018Meetup Junio Data Analysis with python 2018
Meetup Junio Data Analysis with python 2018
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptx
 
Tips and Tricks for Data Visualization in Python
Tips and Tricks for Data Visualization in PythonTips and Tricks for Data Visualization in Python
Tips and Tricks for Data Visualization in Python
 
Predictive modeling
Predictive modelingPredictive modeling
Predictive modeling
 

Plus de Maulik Borsaniya

Dragon fruit-nutrition-facts
Dragon fruit-nutrition-factsDragon fruit-nutrition-facts
Dragon fruit-nutrition-factsMaulik Borsaniya
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAChapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAMaulik Borsaniya
 
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYAPYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYAMaulik Borsaniya
 
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYAPYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYAMaulik Borsaniya
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
 
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...Maulik Borsaniya
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAChapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAMaulik Borsaniya
 

Plus de Maulik Borsaniya (7)

Dragon fruit-nutrition-facts
Dragon fruit-nutrition-factsDragon fruit-nutrition-facts
Dragon fruit-nutrition-facts
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAChapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
 
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYAPYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
 
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYAPYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
 
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAChapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
 

Dernier

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Data Visualization with Matplotlib in Python

  • 1. Chapter – 4 Data Science with Python Intro to Data Visualization with Matplotlib Prof. Maulik Borsaniya Maulik Borsaniya - Gardividyapith
  • 2. Data Visualization  Data visualization is a very important part of data analysis. You can use it to explore your data. If you understand your data well, you’ll have a better chance to find some insights. Finally, when you find any insights, you can use visualizations again to be able to share your findings with other people.  However, the idea here is to learn the fundamentals of Data Visualization and Matplotlib. So, our plots will be much simpler than that example. Maulik Borsaniya - Gardividyapith
  • 3. Basic Visualization Rules  Before we look at some kinds of plots, we’ll introduce some basic rules. Those rules help us make nice and informative plots instead of confusing ones. Steps i. The first step is to choose the appropriate plot type. If there are various options, we can try to compare them, and choose the one that fits our model the best. ii. Second, when we choose your type of plot, one of the most important things is to label your axis. If we don’t do this, the plot is not informative enough. iii. Third, we can add a title to make our plot more informative. Maulik Borsaniya - Gardividyapith
  • 4. IV Fourth, add labels for different categories when needed. V Five, optionally we can add a text or an arrow at interesting data points. VI Six, in some cases we can use some sizes and colors of the data to make the plot more informative. Maulik Borsaniya - Gardividyapith
  • 5. What is Matplotlib ?  Matplotlib is a python library used to create 2D graphs and plots by using python scripts. It has a module named pyplot which makes things easy for plotting by providing feature to control line styles, font properties, formatting axes etc. It supports a very wide variety of graphs and plots namely - histogram, bar charts, power spectra, error charts etc.  It is used along with NumPy to provide an environment that is an effective open source alternative for MatLab.  Pyplot is a matplotlib module which provides a MATLAB-like interface.  Matplotlib is designed to be as usable as MATLAB, with the ability to use Python, and the advantage of being free and open-source. Maulik Borsaniya - Gardividyapith
  • 6. How to install Matplotlib ?  First of all you need to download Python from python.org .Which must be Latest version.  Installing in windows you need to type following command in CMD. python –mpip install -U pip python –mpip install -U matplotlib  For Ubuntu. sudo apt-get build-dep python-matplotlib Maulik Borsaniya - Gardividyapith
  • 7. Simple Example of Plotting(Sine wave form) import numpy as np import matplotlib.pyplot as plt # Compute the x and y coordinates for points on a sine curve x = np.arange(0, 3 * np.pi, 0.1) y = np.sin(x) plt.title("sine wave form") # Plot the points using matplotlib plt.plot(x, y) plt.show() Maulik Borsaniya - Gardividyapith
  • 8. Sr.No. Parameter & Description 1 Start The start of an interval. If omitted, defaults to 0 2 Stop The end of an interval (not including this number) 3 Step Spacing between values, default is 1 4 dtype Data type of resulting ndarray. If not given, data type of input is used numpy.arange(start, stop, step, dtype) The constructor takes the following parameters Maulik Borsaniya - Gardividyapith
  • 9. Scatter Plot  this type of plot shows all individual data points. Here, they aren’t connected with lines. Each data point has the value of the x-axis value and the value from the y-axis values. This type of plot can be used to display trends or correlations.  In data science, it shows how 2 variables compare. To make a scatter plot with Matplotlib, we can use the plt.scatter()function. Again, the first argument is used for the data on the horizontal axis, and the second - for the vertical axis. Maulik Borsaniya - Gardividyapith
  • 10. Example Scatter Plot import matplotlib.pyplot as plt temp = [30, 32, 33, 28.5, 35, 29, 29] ice_creams_count = [100, 115, 115, 75, 125, 79, 89] plt.scatter(temp, ice_creams_count) plt.title("Temperature vs. Sold ice creams") plt.xlabel("Temperature") plt.ylabel("Sold ice creams count") plt.show() Maulik Borsaniya - Gardividyapith
  • 11. Bar chart  represents categorical data with rectangular bars. Each bar has a height corresponds to the value it represents. It’s useful when we want to compare a given numeric value on different categories. It can also be used with 2 data series.  To make a bar chart with Maplotlib, we’ll need the plt.bar() function. Maulik Borsaniya - Gardividyapith
  • 12. E.g.. Bar Chart # Our data import matplotlib.pyplot as plt labels = ["JavaScript", "Java", "Python", "C#"] usage = [69.8, 45.3, 38.8, 34.4] # Generating the y positions. Later, we'll use them to replace them with labels. y_positions = range(len(labels)) # Creating our bar plot plt.bar(y_positions, usage) plt.xticks(y_positions, labels) plt.ylabel("Usage (%)") plt.title("Programming language usage") plt.show() Maulik Borsaniya - Gardividyapith
  • 13. Pie chart a circular plot, divided into slices to show numerical proportion. They are widely used in the business world. However, many experts recommend to avoid them. The main reason is that it’s difficult to compare the sections of a given pie chart. Also, it’s difficult to compare data across multiple pie charts. In many cases, they can be replaced by a bar chart. Maulik Borsaniya - Gardividyapith
  • 14. Pie Chart Example import matplotlib.pyplot as plt sizes = [25, 20, 45, 10] labels = ["Cats", "Dogs", "Tigers", "Goats"] plt.pie(sizes, labels = labels, autopct = "%.2f")#float and persentage value plt.axes().set_aspect("equal")#auto #num #aspect ratio plt.show() Maulik Borsaniya - Gardividyapith
  • 15. Working With Data Science And Panda  Pandas is an open-source Python Library used for high- performance data manipulation and data analysis using its powerful data structures. Python with pandas is in use in a variety of academic and commercial domains, including Finance, Economics, Statistics, Advertising, Web Analytics, and more.  Using Pandas, we can accomplish five typical steps in the processing and analysis of data, regardless of the origin of data — load, organize, manipulate, model, and analyze the data.  Below are the some of the important features of Pandas which is used specifically for Data processing and Data analysis work. Maulik Borsaniya - Gardividyapith
  • 16. If you want to work with data & sheets you need to do and install Panda First. Installation steps In Windows -> CMD - > Go to the specific python installed directory.  type following command over there and keep breathing…( ) C:>Python pip install pandas For Ubuntu -> Terminal Type following commands. >> sudo pip install pandas Maulik Borsaniya - Gardividyapith
  • 17. Pandas handles data through Series, Data Frame, and Panel. We will see some examples from each of these. Pandas Series  Series is a one-dimensional labeled array capable of holding data of any type (integer, string, float, python objects, etc.). The axis labels are collectively called index. A pandas Series can be created using the following constructor Syntax : pandas. Series( data, index, dtype, copy) #import the pandas library and aliasing as pd import pandas as pd import numpy as np data = np.array(['a','b','c','d']) s = pd.Series(data) print s Maulik Borsaniya - Gardividyapith
  • 18. Pandas Data Frame  A Data frame is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and columns. A pandas Data Frame can be created using the following constructor  Syntax : pandas.DataFrame( data, index, columns, dtype, copy) Eg. import pandas as pd data = {'Name':['Tom', 'Jack', 'Steve', 'Ricky'],'Age':[28,34,29,42]} df = pd.DataFrame(data, index=['rank1','rank2','rank3','rank4']) print df Maulik Borsaniya - Gardividyapith
  • 19. What is Data Frame ?  A Data frame is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and columns. Features of Data Frame  Potentially columns are of different types  Size – Mutable  Labeled axes (rows and columns)  Can Perform Arithmetic operations on rows and columns  Structure Maulik Borsaniya - Gardividyapith
  • 20. Maulik Borsaniya - Gardividyapith
  • 21. Data frame from list import pandas as pd data = [1,2,3,4,5] df = pd.DataFrame(data) print (df) E.g.2 import pandas as pd data = [['Alex',10],['Bob',12],['Clarke',13]] df = pd.DataFrame(data,columns=['Name','Age']) print df E.g.3 import pandas as pd data = [['Alex',10],['Bob',12],['Clarke',13]] Df=pd.DataFrame(data,columns=['Name','Age'],dtype=float) print df Maulik Borsaniya - Gardividyapith
  • 22. Creating Data Frame from Dictionary import pandas as pd data = {'Name':['Tom', 'Jack', 'Steve', 'Ricky'],'Age':[28,34,29,42]} df = pd.DataFrame(data) print df Maulik Borsaniya - Gardividyapith
  • 23. Reading Data From CSV / Excel import pandas as pd data = pd.read_csv('C:Python34/sheet1.csv') print (data) Reading Specific Row – Eg.2 import pandas as pd data = pd.read_csv('C:Python34/sheet1.csv') # Slice the result for first 5 rows print (data[0:5]['salary']) #for Excel you can use read_excel….. Maulik Borsaniya - Gardividyapith