SlideShare a Scribd company logo
Introduction to Matplotlib
Introduction to Artificial Intelligence
Introduction to Matplotlib
• Matplotlib is a widely-used Python library for creating a variety of
static, animated, and interactive plots.
• It helps visualize data, which makes understanding trends, patterns,
and comparisons much easier.
• Example: Importing Matplotlib
import matplotlib.pyplot as plt
pyplot is a sub-module of Matplotlib. We use plt as a shorthand alias,
which is standard and widely used in tutorials and documentation.
Basics of Plotting with pyplot
• The plot() function in pyplot creates line graphs. This function accepts
lists (or arrays) for the x and y coordinates.
• x and y represent the data points.
• xlabel, ylabel, and title add labels to the axes and title the plot.
• Task: Modify the data in x and y lists
to see how the plot changes.
Customizing Line Style and Colors
• Customizing the appearance of the line can make plots visually
appealing and help differentiate between multiple data sets.
• color='red' changes the line color to red.
• linestyle='--' uses a dashed line style.
• marker='o' adds circular markers at each data point.
• Try different colors ('blue', 'green'), line styles ('-', ':'), and markers
('x', '*') to explore customization.
Adding Multiple Lines to the Same Plot
• we can use multiple lines if we want to compare multiple data series
in a single plot.
• label parameter names each line; plt.legend() displays the legend,
making it easier to distinguish between the series.
• Task: Add a third line with their own
data and customize its appearance.
Bar Plots
• Bar plots display data in rectangular bars, ideal for comparing
categories.
• plt.bar() creates a bar plot, with categories on the x-axis and values as
heights of the bars.
• Task: Change the values list to represent different data (e.g., scores
or population).
Scatter Plots
• Scatter plots are used to show relationships between two variables.
• plt.scatter() plots each point individually, useful for analyzing data
distribution.
• Task: Use different colors and markers to represent data from two
groups.
Histograms
• Histograms are useful for showing data distribution, especially with
large datasets.
• np.random.normal() generates 100 random data points.
• plt.hist() creates the histogram, where bins=10 means 10 intervals.
• Task: Change bins to see how it affects the granularity of the
histogram.
Using Subplots for Multiple Plots in One
Figure
• Subplots allow multiple plots in a single figure, useful for comparing
related data.
• fig, axs = plt.subplots(1, 2) creates a 1x2 grid.
• axs[0] and axs[1] refer to the first and second subplot.
• Task: Add a third subplot showing a bar plot.
Advanced Customization Techniques
• Advanced techniques make plots more informative and visually
engaging.
• linewidth=2 adjusts line thickness.
• grid=True adds a background grid.
• xlim and ylim set the range for x and y axes.
• Task: Experiment with different xlim
and ylim values to see how it changes
plot focus.
MINI PROJECTS
Sales Comparison Plot
• plot weekly sales data for two products, customize it with labels, title,
and legend.
Temperature Variation Plot
• Visualize temperature changes over a week using a line plot and a
scatter plot in subplots.
Monthly Expenses Bar Chart
• Visualize monthly expenses in different categories (like groceries, rent,
entertainment, and utilities) using a bar chart.
Survey Data Pie Chart
• Create a pie chart to display survey results (Visualize survey data from
a poll about favourite programming languages, showing each
language’s share.)
Sales Trend Comparison Line Plot
• Compare monthly sales trends for two products (Plot the sales of two
products over 12 months to see trends and seasonal effects.)
Population Distribution Histogram
• Display population distribution across age groups (Plot a histogram of
ages within a community to show distribution.)
Weather Data Subplots
• Create subplots to display monthly average temperature and rainfall
(Use subplots to plot monthly temperature and rainfall for a city).

More Related Content

PPTX
MatplotLib.pptx
PPTX
Matplotlib yayyyyyyyyyyyyyin Python.pptx
PPTX
Introduction to matplotlib
PPTX
matplotlib.pptxdsfdsfdsfdsdsfdsdfdsfsdf cvvf
PPTX
Unit III for data science engineering.pptx
PPTX
Unit3-v1-Plotting and Visualization.pptx
DOCX
Data visualization using py plot part i
PPTX
Python Visualization API Primersubplots
MatplotLib.pptx
Matplotlib yayyyyyyyyyyyyyin Python.pptx
Introduction to matplotlib
matplotlib.pptxdsfdsfdsfdsdsfdsdfdsfsdf cvvf
Unit III for data science engineering.pptx
Unit3-v1-Plotting and Visualization.pptx
Data visualization using py plot part i
Python Visualization API Primersubplots

Similar to a9bf73_Introduction to Matplotlib01.pptx (20)

PDF
12-IP.pdf
PPTX
UNIT_4_data visualization.pptx
PPTX
Matplotlib_Presentation jk jdjklskncncsjkk
PPTX
Python chart plotting using Matplotlib.pptx
PPTX
Introduction to Matplotlib Library in Python.pptx
PPTX
2. Python Library Matplotlibmmmmmmmm.pptx
PPTX
UNIT-5-II IT-DATA VISUALIZATION TECHNIQUES
PPTX
Matplot Lib Practicals artificial intelligence.pptx
PPTX
Introduction to Pylab and Matploitlib.
PPTX
Matplotlib.pptx for data analysis and visualization
PDF
UNIT-2.data exploration and visualization
PDF
Chapter3_Visualizations2.pdf
PPTX
Visualization and Matplotlib using Python.pptx
PDF
Lecture 34 & 35 -Data Visualizationand itd.pdf
PDF
UNit-III. part 2.pdf
PPTX
Python Pyplot Class XII
PPTX
matplotlib _
PPTX
Python_Matplotlib_13_Slides_With_Diagrams.pptx
PPTX
data analytics and visualization CO4_18_Data Types for Plotting.pptx
PDF
711118749-FDS-UNIT-5-PPT.pdf is used to the engineering students
12-IP.pdf
UNIT_4_data visualization.pptx
Matplotlib_Presentation jk jdjklskncncsjkk
Python chart plotting using Matplotlib.pptx
Introduction to Matplotlib Library in Python.pptx
2. Python Library Matplotlibmmmmmmmm.pptx
UNIT-5-II IT-DATA VISUALIZATION TECHNIQUES
Matplot Lib Practicals artificial intelligence.pptx
Introduction to Pylab and Matploitlib.
Matplotlib.pptx for data analysis and visualization
UNIT-2.data exploration and visualization
Chapter3_Visualizations2.pdf
Visualization and Matplotlib using Python.pptx
Lecture 34 & 35 -Data Visualizationand itd.pdf
UNit-III. part 2.pdf
Python Pyplot Class XII
matplotlib _
Python_Matplotlib_13_Slides_With_Diagrams.pptx
data analytics and visualization CO4_18_Data Types for Plotting.pptx
711118749-FDS-UNIT-5-PPT.pdf is used to the engineering students
Ad

Recently uploaded (20)

PDF
Complications of Minimal Access Surgery at WLH
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Institutional Correction lecture only . . .
PDF
Sports Quiz easy sports quiz sports quiz
PDF
01-Introduction-to-Information-Management.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Pre independence Education in Inndia.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Cell Types and Its function , kingdom of life
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Cell Structure & Organelles in detailed.
PPTX
GDM (1) (1).pptx small presentation for students
Complications of Minimal Access Surgery at WLH
human mycosis Human fungal infections are called human mycosis..pptx
Institutional Correction lecture only . . .
Sports Quiz easy sports quiz sports quiz
01-Introduction-to-Information-Management.pdf
PPH.pptx obstetrics and gynecology in nursing
2.FourierTransform-ShortQuestionswithAnswers.pdf
VCE English Exam - Section C Student Revision Booklet
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Renaissance Architecture: A Journey from Faith to Humanism
Pre independence Education in Inndia.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Cell Types and Its function , kingdom of life
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Insiders guide to clinical Medicine.pdf
Basic Mud Logging Guide for educational purpose
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Cell Structure & Organelles in detailed.
GDM (1) (1).pptx small presentation for students
Ad

a9bf73_Introduction to Matplotlib01.pptx

  • 1. Introduction to Matplotlib Introduction to Artificial Intelligence
  • 2. Introduction to Matplotlib • Matplotlib is a widely-used Python library for creating a variety of static, animated, and interactive plots. • It helps visualize data, which makes understanding trends, patterns, and comparisons much easier. • Example: Importing Matplotlib import matplotlib.pyplot as plt pyplot is a sub-module of Matplotlib. We use plt as a shorthand alias, which is standard and widely used in tutorials and documentation.
  • 3. Basics of Plotting with pyplot • The plot() function in pyplot creates line graphs. This function accepts lists (or arrays) for the x and y coordinates. • x and y represent the data points. • xlabel, ylabel, and title add labels to the axes and title the plot. • Task: Modify the data in x and y lists to see how the plot changes.
  • 4. Customizing Line Style and Colors • Customizing the appearance of the line can make plots visually appealing and help differentiate between multiple data sets. • color='red' changes the line color to red. • linestyle='--' uses a dashed line style. • marker='o' adds circular markers at each data point. • Try different colors ('blue', 'green'), line styles ('-', ':'), and markers ('x', '*') to explore customization.
  • 5. Adding Multiple Lines to the Same Plot • we can use multiple lines if we want to compare multiple data series in a single plot. • label parameter names each line; plt.legend() displays the legend, making it easier to distinguish between the series. • Task: Add a third line with their own data and customize its appearance.
  • 6. Bar Plots • Bar plots display data in rectangular bars, ideal for comparing categories. • plt.bar() creates a bar plot, with categories on the x-axis and values as heights of the bars. • Task: Change the values list to represent different data (e.g., scores or population).
  • 7. Scatter Plots • Scatter plots are used to show relationships between two variables. • plt.scatter() plots each point individually, useful for analyzing data distribution. • Task: Use different colors and markers to represent data from two groups.
  • 8. Histograms • Histograms are useful for showing data distribution, especially with large datasets. • np.random.normal() generates 100 random data points. • plt.hist() creates the histogram, where bins=10 means 10 intervals. • Task: Change bins to see how it affects the granularity of the histogram.
  • 9. Using Subplots for Multiple Plots in One Figure • Subplots allow multiple plots in a single figure, useful for comparing related data. • fig, axs = plt.subplots(1, 2) creates a 1x2 grid. • axs[0] and axs[1] refer to the first and second subplot. • Task: Add a third subplot showing a bar plot.
  • 10. Advanced Customization Techniques • Advanced techniques make plots more informative and visually engaging. • linewidth=2 adjusts line thickness. • grid=True adds a background grid. • xlim and ylim set the range for x and y axes. • Task: Experiment with different xlim and ylim values to see how it changes plot focus.
  • 12. Sales Comparison Plot • plot weekly sales data for two products, customize it with labels, title, and legend.
  • 13. Temperature Variation Plot • Visualize temperature changes over a week using a line plot and a scatter plot in subplots.
  • 14. Monthly Expenses Bar Chart • Visualize monthly expenses in different categories (like groceries, rent, entertainment, and utilities) using a bar chart.
  • 15. Survey Data Pie Chart • Create a pie chart to display survey results (Visualize survey data from a poll about favourite programming languages, showing each language’s share.)
  • 16. Sales Trend Comparison Line Plot • Compare monthly sales trends for two products (Plot the sales of two products over 12 months to see trends and seasonal effects.)
  • 17. Population Distribution Histogram • Display population distribution across age groups (Plot a histogram of ages within a community to show distribution.)
  • 18. Weather Data Subplots • Create subplots to display monthly average temperature and rainfall (Use subplots to plot monthly temperature and rainfall for a city).