Introduction to Matplotlib
A Python Library for Data
Visualization
Prepared by Muhammad Sarfraz
What is Matplotlib?
• - Matplotlib is a Python library for data
visualization.
• - Provides control over plots similar to
MATLAB.
• - Works with NumPy and Pandas for scientific
computing.
• - Allows customization of graphs and charts.
Why Use Matplotlib?
• - Versatile: Can create line plots, bar charts,
histograms, etc.
• - Highly customizable.
• - Works well with Pandas and NumPy.
• - Supports interactive plotting.
Installation
• Install Matplotlib using pip:
• pip install matplotlib
Importing Required Libraries
• import matplotlib.pyplot as plt
• import numpy as np
Simple Line Plot
• x = np.linspace(0, 10, 100)
• y = np.sin(x)
• plt.plot(x, y)
• plt.show()
Bar Chart Example
• categories = ['A', 'B', 'C', 'D']
• values = [10, 20, 15, 25]
• plt.bar(categories, values)
• plt.show()
Histogram Example
• data = np.random.randn(1000)
• plt.hist(data, bins=30, color='blue', alpha=0.7)
• plt.show()
Scatter Plot Example
• x = np.random.rand(50)
• y = np.random.rand(50)
• plt.scatter(x, y, color='red')
• plt.show()
Pie Chart Example
• labels = ['A', 'B', 'C', 'D']
• sizes = [15, 30, 45, 10]
• plt.pie(sizes, labels=labels, autopct='%1.1f%
%')
• plt.show()
Customizing Plots
• - Change line styles and colors.
• - Add titles, labels, and legends.
• - Adjust figure size and save plots.
Conclusion
• - Matplotlib is a powerful library for creating
visualizations.
• - Provides extensive customization options.
• - Works well with Pandas and NumPy for data
analysis.
• - Suitable for both simple and complex plots.

Introduction_to_Matplotlibpresenatration.pptx

  • 1.
    Introduction to Matplotlib APython Library for Data Visualization Prepared by Muhammad Sarfraz
  • 2.
    What is Matplotlib? •- Matplotlib is a Python library for data visualization. • - Provides control over plots similar to MATLAB. • - Works with NumPy and Pandas for scientific computing. • - Allows customization of graphs and charts.
  • 3.
    Why Use Matplotlib? •- Versatile: Can create line plots, bar charts, histograms, etc. • - Highly customizable. • - Works well with Pandas and NumPy. • - Supports interactive plotting.
  • 4.
    Installation • Install Matplotlibusing pip: • pip install matplotlib
  • 5.
    Importing Required Libraries •import matplotlib.pyplot as plt • import numpy as np
  • 6.
    Simple Line Plot •x = np.linspace(0, 10, 100) • y = np.sin(x) • plt.plot(x, y) • plt.show()
  • 7.
    Bar Chart Example •categories = ['A', 'B', 'C', 'D'] • values = [10, 20, 15, 25] • plt.bar(categories, values) • plt.show()
  • 8.
    Histogram Example • data= np.random.randn(1000) • plt.hist(data, bins=30, color='blue', alpha=0.7) • plt.show()
  • 9.
    Scatter Plot Example •x = np.random.rand(50) • y = np.random.rand(50) • plt.scatter(x, y, color='red') • plt.show()
  • 10.
    Pie Chart Example •labels = ['A', 'B', 'C', 'D'] • sizes = [15, 30, 45, 10] • plt.pie(sizes, labels=labels, autopct='%1.1f% %') • plt.show()
  • 11.
    Customizing Plots • -Change line styles and colors. • - Add titles, labels, and legends. • - Adjust figure size and save plots.
  • 12.
    Conclusion • - Matplotlibis a powerful library for creating visualizations. • - Provides extensive customization options. • - Works well with Pandas and NumPy for data analysis. • - Suitable for both simple and complex plots.