Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
68 views
35 pages
Practical Guide To Matplotlib For Data Science - 1689973407325
Practical Guide to Matplotlib for Data Science - 1689973407325
Uploaded by
Dridi Amani
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save Practical Guide to Matplotlib for Data Science - 1... For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
68 views
35 pages
Practical Guide To Matplotlib For Data Science - 1689973407325
Practical Guide to Matplotlib for Data Science - 1689973407325
Uploaded by
Dridi Amani
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save Practical Guide to Matplotlib for Data Science - 1... For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save Practical Guide to Matplotlib for Data Science - 1... For Later
You are on page 1
/ 35
Search
Fullscreen
micelles Ee ules) to Matploilio for Data Science ‘S) A STEP-BY-STEP GUIDE |Table of Contents Introduction to Matplotlib © 1.1 What is Matplotlib? © 1.2 Why Use Matplotlib in Data Science? Installation and Setup © 2.1 Installing Matplotlib © 2.2 Importing Matplotlib Basic Plots © 3.1 Line Plots © 3.2 Scatter Plots © 3.3 Bar Plots © 3.4 Histograms Customizing Plots © 4.1 Figure Size and Resolution © 4.2 Labels and Titles © 4.3 Legends © 4.4 Colors, Styles, and Markers © 4.5 Axis Limits and Ticks Multiple Subplots © 5.1 Creating Subplots © 5.2 Customizing Subplots © 5.3 Sharing Axis Labels Advanced Plots © 6.1 Pie Charts © 6.2 Box Plots © 6.3 Heatmaps © 6.4 3D Plots Data Visualization Tips © 7.1 Choosing the Right Plot © 7.2 Using Colors Effectively © 7.3 Handling Missing Data © 7.4 Adding Annotations and Text Saving and Exporting Plots © 8.1 Saving Plots to File © 8.2 Exporting Plots to Different Formats Real-World Examples © 9.1 Plotting Time Series Data © 9.2 Visualizing Categorical Data © 9.3 Geospatial Data Visualization Conclusion @RAMCHANDRAPADWAL~ Introduction to Matplottilo1.1 WHAT IS MATPLOTLIB? Matplotlib is a popular data visualization library in Python that provides a wide range of plotting functions and tools. It allows data scientists to create high-quality charts, graphs, and visualizations with ease. 1.2 WHY USE MATPLOTLIB IN DATA SCIENCE? Matplotlib is widely used in data science due to its flexibility, extensive functionality, and compatibility with other libraries like NumPy and Pandas. It offers a vast array of plot types, customization options, and excellent documentation, making it an essential tool for data exploration and presentation. @RAMCHANDRAPADWAL,fe aaaa\ 4 Installation and S10 /@2.1 Installing Matplotlib To install Matplotlib, you can use pip, the Python package manager. Open a terminal and execute the following command: pip install matplotlib 2.2 Importing Matplotlib Before using Matplotlib, import it into your Python script or notebook using the following statement: Pesta Canoe @RAMCHANDRAPADWAL,fo aaa aN ec} (oleae Sys Son @lks ‘S) Tee mae Lene3.1 Line Plots | Line plots are useful for visualizing the relationship between | two variables over a continuous interval. To create a line plot, use the plot() function in Matplotlib. EXAMPLE: Chats Cob 7 SC Lae ee sed plot(x, y) aera EUS Rotola show() OUTPUT: Line Plot Yaxis @RAMCHANDRAPADWAL3.2 Scatter Plots Scatter plots are ideal for displaying the distribution and relationship between two numerical variables. Matplotlib provides the scatter() function for creating scatter plots. EXAMPLE: POSS ISe LE aa bd catter(x Pia ssl Pcaagersn plt.title( plt.show() OUTPUT: Scatter Plot ¥axis lo 15 20 25 30 35 40 45 50 Xaxis @RAMCHANDRAPADWAL3.3 Bar Plots Bar plots are effective for comparing categorical data or showing the distribution of a single variable. Matplotlib offers the bar() and barh() functions for creating vertical and horizontal bar plots, respectively. EXAMPLE: Teese 7 lee ed categories values = [10, plt.bar(categories, values) nee sean aan EL nt seen an plt.show() OUTPUT: Bar Plot Values oo A 8 c D Categories @RAMCHANDRAPADWAL,3.4 Histograms Histograms are useful for visualizing the distribution of a continuous variable. Matplotlib provides the hist() function to create histograms. EXAMPLE: matplotlib.pyplot as plt eee) Ce ecu ecg Prarie) earn » BBtIasKt Recatye -show() OUTPUT: Histogram 80 2 g Frequency =3 2 =1 ° B 3 Values @RAMCHANDRAPADWAL,CHAPTER N.4 OUSrelanvaiale} Plots4.1 Figure Size and Resolution Matplotlib allows you to customize the size and resolution of your plots using the figure() function EXAMPLE: matplotlib.pyplot [saa ) Uses cect St CRO Co plt.show() ouTPUT: @RAMCHANDRAPADWAL,4.2 Labels and Titles You can add labels to the x-axis, y-axis, and title of your plot using the xlabel(), ylabel(), and title() functions. EXAMPLE: DOSS ISe LES aa hd stare en) [tae plt. ylabel( istaesot| how’) OUTPUT: Line Plot ¥axis @RAMCHANDRAPADWAL4.3 Legends To add a legend to your plot, use the legend() function. You can specify the position of the legend and add labels for each data series. EXAMPLE: matplotlib.pyplot as plt Cota trae sens aE Pye eTSee) Br PotaeCUCierd — series 1 — series 2 @RAMCHANDRAPADWAL4.4 Colors, Styles, and Markers Matplotlib allows you to customize the colors, line styles, and markers of your plots. You can use a wide range of predefined colors and markers or define your own. EXAMPLE: Ce RIEU Cae Sed Faces ACU p teen aoe @RAMCHANDRAPADWAL,4.5 Axis Limits and Ticks You can set the limits and ticks for the x-axis and y-axis using the xtim(), ylim(), and xticks(), yticks() functions, respectively EXAMPLE: iT SSE CN SC aeee ed [stat eae Pstae sec On OUTPUT: 207 @RAMCHANDRAPADWALSen Mirels Subplots5.1 Creating Subplots Matplotlib allows you to create multiple subplots within a single figure using the subplots() function. EXAMPLE: PL Cot nZone ad Par axes. flatten() (data, bins ) OUTPUT: 10 10 ° 8 8 ° 6 6 e 4 4 ° 2 240 1 2 3 4 5 1 2 3 4 5 20 80 1s 60 10 40 5 20 0 ° A B ig D -2 0 2 @RAMCHANDRAPADWAL,5.2 Customizing Subplots You can customize each subplot individually by accessing them through the axes object. EXAMPLE: Ce CSE UN Coed fig, axes = plt.subplots(nrows=2, ncols=2) , ax4 = axes. flatten() cmBeTsnd seem) Eee Cansei Cramatong 10 @RAMCHANDRAPADWAL,5.3 Sharing Axis Labels When creating subplots, you can share the x-axis or y-axis labels across multiple subplots. EXAMPLE: Ceo Se LMT aCe yc Mersretir Peon eae vc vce sto ule) Pye Te) OUTPUT: 10 08 06 04 02 0.0 10 08 06 04 02 0.0 00 02 04 06 08 10 00 02 04 06 08 10 @RAMCHANDRAPADWALCoN aas aN Ro} Advanced Plots_ 6.1 Pie Charts Pie charts are ideal for displaying proportions and percentages of different categories. Matplotlib provides the pie() function for creating pie charts. EXAMPLE: Cease, aes 1 1 SEMEL ae OuTPUT: Pie Chart6.2 Box Plots Box plots are useful for visualizing the distribution of numerical data through quartiles. Matplotlib offers the boxplot() function for creating box plots. EXAMPLE: DESC LSE Ue 7) Cea Ses Chem recur CMake plt.boxplot (data) SaEUSNG BES OUTPUT: Box Plot | {0 Values 1 2 3 Groups6.3 Heatmaps Heatmaps are excellent for visualizing matrices or correlation matrices. Matplotlib provides the imshow() function for creating heatmaps. EXAMPLE: Ce SCS ECM eg oe Ce ecu cUC La TICE CL mototlg show() OUTPUT: Ded 10) SCLC Heatmap6.4 3D Plots Matplotlib also supports 3D plotting for visualizing complex data. You can create 3D plots using the plot_surface() function. EXAMPLE: ee CStCeey ca ao) fig = plt.figure() Deen CRC rete emetsty| pit.show() OUTPUT: 3D Plot | } 075 } 050 to2s } 0.00 {0.25 }-0.50 }-075 4S ° 2Dae WATS re |Izs)i(eya) Tips— 7:1 Choosing the Right Plot Consider the nature of your data and the information you want to convey when selecting the appropriate plot type. Different plot types are suitable for different data types and objectives. 7.2 Using Colors Effectively Choose colors that are visually appealing, easy to distinguish, and accessible to color-blind individuals. Matplotlib provides a wide range of color palettes to choose from 7.3 Handling Missing Data Consider how missing data should be handled in your plots. You can choose to exclude missing values or display them in a specific way, such as using markers or different colors. 74 Adding Annotations and Text Annotations and text can provide additional context and insights to your plots. Matplotlib offers various functions for adding text, labels, and annotations to specific plot elements. | GRAVCHANORAPAOWAL_ Saving and Exporting Plots— 8.1 Saving Plots to File You can save your Matplotlib plots to various file formats, such as PNG, PDF, SVG, or JPEG, using the savefig() function. EXAMPLE: matplotlib.pyplot as plt [yt e ee) Ptaee irene 8.2 Exporting Plots to Different Formats Matplotlib supports exporting plots to different formats using the savefig() function. You can specify the desired file format using the file extension. EXAMPLE: DTC ioUn SCL om ood plt.plot(x, y) eaerset |~~ Real-World Examples9.1 Plotting Time Series Data Time series data is a common type of data encountered in data science. Matplotlib allows you to visualize and analyze time series data effectively. EXAMPLE: Cte rseC 7 SCL ye CCU eRe) Cle webs AG Cre Ocul e ee Cie ce Pease K Pye KG eaesaae| show() EXAMPLE: Time Series Plot 130 120 1984 1988 1992 1996 2000 2004 2008 2012 2016 Date— 9.2 Visualizing Categorical Data When working with categorical data, Matplotlib provides various plot types, such as bar plots, stacked bar plots, and pie charts, to effectively display and compare different categories. EXAMPLE: aac seC Ry Cae eeed ee CU Oe) Cee ee emery SBE cotary EXAMPLE: Bar Plot 120 100 80 Values 60 40 20 = nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnns | Categories ’AMICHANDRAPADWAL.— 9.3 Geospatial Data Visualization For geospatial data visualization, Matplotlin provides functionality to plot data on maps. You can display various geospatial features such as points, lines, polygons, and choropleth maps. EXAMPLE: Psbaeseae how() EXAMPLE: World Map 75 50 25 -50 -75 -150 -100 -50 0 50 100 150oon Naam Conclusion Matplotlib is a powerful and versatile data visualization library for Python. In this guide, we covered the basics of Matplotlib and explored various plot types, customization options, and advanced features. By following this practical guide, you should now be equipped with the knowledge and tools to create visually appealing and informative plots for your data science projects. Experiment with different plot types and customization options to unleash the full potential of Matplotlib. Happy plotting!
You might also like
Matplotlib Review 2021 Complete
PDF
No ratings yet
Matplotlib Review 2021 Complete
352 pages
Practical Data Science
PDF
No ratings yet
Practical Data Science
121 pages
FME Transformer Reference Guide
PDF
No ratings yet
FME Transformer Reference Guide
62 pages
Python Slides PDF
PDF
No ratings yet
Python Slides PDF
35 pages
22 Python Libraries For Geospatial Data Analysis
PDF
No ratings yet
22 Python Libraries For Geospatial Data Analysis
10 pages
Practical Guide To Matplotlib For Data Science
PDF
100% (1)
Practical Guide To Matplotlib For Data Science
35 pages
Advanced Visualization For Data Scientists With Matplotlib
PDF
No ratings yet
Advanced Visualization For Data Scientists With Matplotlib
38 pages
Heatmap Instruction
PDF
No ratings yet
Heatmap Instruction
9 pages
Python Matplotlib Data Visualization
PDF
No ratings yet
Python Matplotlib Data Visualization
32 pages
Matplotlib Cheat Sheet (For Intermediate Users)
PDF
No ratings yet
Matplotlib Cheat Sheet (For Intermediate Users)
8 pages
Wrangling Webinar
PDF
No ratings yet
Wrangling Webinar
151 pages
1 - Interactive Data Visualization With Bokeh
PDF
No ratings yet
1 - Interactive Data Visualization With Bokeh
31 pages
Dev Lecture Notes UNIT-2
PDF
No ratings yet
Dev Lecture Notes UNIT-2
57 pages
Advanced Visualizations
PDF
No ratings yet
Advanced Visualizations
32 pages
Analyzing IoT Data in Python Chapter1
PDF
100% (1)
Analyzing IoT Data in Python Chapter1
27 pages
6.customizing Seaborn Plots PDF
PDF
No ratings yet
6.customizing Seaborn Plots PDF
17 pages
Python Libraries Cheat Sheets
PDF
No ratings yet
Python Libraries Cheat Sheets
6 pages
8 Best Python Cheat Sheets For Beginners and Intermediate Learners
PDF
100% (1)
8 Best Python Cheat Sheets For Beginners and Intermediate Learners
13 pages
9.3.2 CDO Operator Categories: Section 5.3
PDF
No ratings yet
9.3.2 CDO Operator Categories: Section 5.3
50 pages
DEV Lecture Notes Unit II
PDF
No ratings yet
DEV Lecture Notes Unit II
57 pages
Machine Learning Basics: 1. General Introduction
PDF
No ratings yet
Machine Learning Basics: 1. General Introduction
46 pages
Pandas For Machine Learning: Acadview
PDF
No ratings yet
Pandas For Machine Learning: Acadview
18 pages
Opencv Python Tutroals
PDF
100% (1)
Opencv Python Tutroals
269 pages
Unit V Data Visualization
PDF
No ratings yet
Unit V Data Visualization
49 pages
Data Visualization Using Seaborn - Towards Data Science
PDF
No ratings yet
Data Visualization Using Seaborn - Towards Data Science
31 pages
Visualizations in Spreadsheets and Tableau
PDF
No ratings yet
Visualizations in Spreadsheets and Tableau
4 pages
Slicing. Both, Numpy Array Indexing and Slicing Will Be Discussed in The Remainder
PDF
No ratings yet
Slicing. Both, Numpy Array Indexing and Slicing Will Be Discussed in The Remainder
50 pages
Pandas
PDF
No ratings yet
Pandas
1,385 pages
Pandas Cheat Sheet
PDF
100% (2)
Pandas Cheat Sheet
6 pages
Pandas Commands
PDF
No ratings yet
Pandas Commands
3 pages
Programmation Météo en Python
PDF
No ratings yet
Programmation Météo en Python
50 pages
Review of Basic Statistical Concepts Hanke
PDF
No ratings yet
Review of Basic Statistical Concepts Hanke
28 pages
Slides 02 Python
PDF
No ratings yet
Slides 02 Python
24 pages
Data Science Cheatsheets PDF
PDF
No ratings yet
Data Science Cheatsheets PDF
9 pages
Visualization With Matplotlib
PDF
No ratings yet
Visualization With Matplotlib
18 pages
Introductory Notes: Matplotlib: Preliminaries
PDF
No ratings yet
Introductory Notes: Matplotlib: Preliminaries
8 pages
Data Visualization - Getting Started With Plotly
PDF
No ratings yet
Data Visualization - Getting Started With Plotly
37 pages
Experiment No: 1 Introduction To Data Analytics and Python Fundamentals Page-1/11
PDF
No ratings yet
Experiment No: 1 Introduction To Data Analytics and Python Fundamentals Page-1/11
8 pages
T-GCPBDML-B - M2 - Data Engineering For Streaming Data - ILT Slides
PDF
No ratings yet
T-GCPBDML-B - M2 - Data Engineering For Streaming Data - ILT Slides
71 pages
Resource - Python Cheat Sheets - Python Programming With Sequences of Data - Y9
PDF
No ratings yet
Resource - Python Cheat Sheets - Python Programming With Sequences of Data - Y9
8 pages
Python Cheat Sheet Dataquest PDF
PDF
No ratings yet
Python Cheat Sheet Dataquest PDF
5 pages
Working With Dates in Pandas: Prepared by Asif Bhat
PDF
No ratings yet
Working With Dates in Pandas: Prepared by Asif Bhat
13 pages
Alteryx Designer Cheat Sheet
PDF
No ratings yet
Alteryx Designer Cheat Sheet
2 pages
Data Exploration & Visualization - Unit 2
PDF
No ratings yet
Data Exploration & Visualization - Unit 2
8 pages
Python Interview Questions
PDF
No ratings yet
Python Interview Questions
8 pages
Statistics For Data Analysis
PDF
No ratings yet
Statistics For Data Analysis
7 pages
Columbia Seaborn Tutorial
PDF
No ratings yet
Columbia Seaborn Tutorial
12 pages
Banking, Finance and Insurance Domain
PDF
No ratings yet
Banking, Finance and Insurance Domain
14 pages
RADAR Documentation 0v6p8
PDF
No ratings yet
RADAR Documentation 0v6p8
81 pages
DSL Pandas
PDF
No ratings yet
DSL Pandas
87 pages
Data Visualization With Tableau: October 26-27, 2017 Sacramento, CA
PDF
No ratings yet
Data Visualization With Tableau: October 26-27, 2017 Sacramento, CA
55 pages
DAX Cheat Sheet
PDF
No ratings yet
DAX Cheat Sheet
10 pages
Eden Nemesis Rs700 Na650 SCH
PDF
No ratings yet
Eden Nemesis Rs700 Na650 SCH
1 page
Data Science Cheat Sheet: KEY Imports
PDF
100% (1)
Data Science Cheat Sheet: KEY Imports
1 page
Pandas Cheat Sheet
PDF
No ratings yet
Pandas Cheat Sheet
2 pages
Figure Style and Scale: Darkgrid Whitegrid Dark White Ticks Darkgrid
PDF
No ratings yet
Figure Style and Scale: Darkgrid Whitegrid Dark White Ticks Darkgrid
15 pages
Yeungnam University School of Mechanical Engineering Syllabus For 0993 Tribology
PDF
No ratings yet
Yeungnam University School of Mechanical Engineering Syllabus For 0993 Tribology
42 pages
Decorator Hand Out
PDF
No ratings yet
Decorator Hand Out
1 page
Decoupling2 WP
PDF
No ratings yet
Decoupling2 WP
16 pages