Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
How to Plot a Graph in Python

How to Plot a Graph in Python

Posted on February 3, 2025February 3, 2025 By Rishabh saini No Comments on How to Plot a Graph in Python

How to Plot a Graph in Python

Python provides one of the most popular plotting libraries called Matplotlib. It is an open-source, cross-platform library for creating 2D plots from data stored in arrays. It is widely used for data visualization, allowing us to represent data using various types of graphs.

Matplotlib was originally conceived by John D. Hunter in 2003. The library has been continuously updated, making it a reliable tool for plotting graphs in Python.

Complete Python Course with Advance topics:-Click here

Installation of Matplotlib

Before using Matplotlib, we need to install it in our Python environment. Open your terminal or prompt and enter the following instrucciones:

pip install matplotlib

This command will install the Matplotlib library along with its dependency packages.

Basic Concept of Matplotlib

A graph consists of several components. Let’s understand these parts:

  • Figure: The overall window that holds one or more plots.
  • Axes: The area where data is plotted; a figure can contain multiple axes.
  • Axis: The scale used to determine the limits of the graph.
  • Artist: All visual elements on the graph, such as text, lines, and markers.

Introduction to Pyplot

Matplotlib provides a subpackage called pyplot, which is designed for quick and easy plotting. The matplotlib.pyplot module contains various functions to create and customize graphs. It allows us to:

  • Create figures and plotting areas
  • Add labels and titles
  • Plot data points and lines

Basic Example of Plotting a Graph

Here’s how you can create a simple line graph using Matplotlib:

from matplotlib import pyplot as plt    

# Plotting data
plt.plot([1,2,3],[4,5,1])    

# Display the graph
plt.show()

Output:

How to Plot a Graph in Python

Plotting Different Types of Graphs

1. Line Graph

A line graph es práctico para mostrar tendencias a lo largo del tiempo.

from matplotlib import pyplot as plt    

x = [1,2,3]    
y = [10,11,12]    

plt.plot(x, y)    
plt.title("Line Graph")    
plt.xlabel("X axis")    
plt.ylabel("Y axis")    
plt.show()

2. Bar Graph

How to Plot a Graph in Python

from matplotlib import pyplot as plt    

Names = ['Arun', 'James', 'Ricky', 'Patrick']    
Marks = [51, 87, 45, 67]    

plt.bar(Names, Marks, color='blue')    
plt.title('Student Results')    
plt.xlabel('Names')    
plt.ylabel('Marks')    
plt.show()

How to Plot a Graph in Python

3. Pie Chart

A pie chart is used to display percentage-based data distribution.

from matplotlib import pyplot as plt    

Players = ['Smith', 'Finch', 'Warner', 'Lumberchane']    
Runs = [42, 32, 18, 24]    
explode = (0.1, 0, 0, 0)  # Emphasizing the first slice

fig, ax = plt.subplots()    
ax.pie(Runs, explode=explode, labels=Players, autopct='%1.1f%%', shadow=True, startangle=90)    
ax.axis('equal')  # Ensuring the pie chart is circular

plt.show()

How to Plot a Graph in Python

4. Histogram

A histogram is empleado para mostrar la distribución de los datos.

from matplotlib import pyplot as plt    

scores = [97,54,45,10,20,10,30,97,50,71,40,49,40,74,95,80,65,82,70,65,55,70,75,60,52,44,43,42,45]    
range_bins = [0,10,20,30,40,50,60,70,80,90,100]    

plt.hist(scores, range_bins, histtype='bar', rwidth=0.8)    
plt.xlabel('Score Percentage')    
plt.ylabel('Number of Students')    
plt.title('Student Score Distribution')    
plt.show()

How to Plot a Graph in Python

5. Scatter Plot

A scatter plot se aplica para examinar la correlación entre dos variables.

from matplotlib import pyplot as plt    

x = [4,8,12]    
y = [19,11,7]    

x2 = [7,10,12]    
y2 = [8,18,24]    

plt.scatter(x, y, label='Group 1', color='b')    
plt.scatter(x2, y2, label='Group 2', color='g')    

plt.title('Scatter Plot')    
plt.xlabel('X axis')    
plt.ylabel('Y axis')    
plt.legend()
plt.show()

How to Plot a Graph in Python

Download New Real Time Projects :-Click here
Complete Advance AI topics:- CLICK HERE


Conclusion

In this tutorial, we explored how to plot graphs in Python using Matplotlib. We covered different types of graphs, including line graphs, bar charts, pie charts, histograms, and scatter plots. Matplotlib provides a flexible and powerful way to visualize data.

To learn more about data visualization in Python, visit updategadh for more in-depth tutorials!


how to plot graph in python using matplotlib
how to plot graph in python using csv file
python graph data structure
python code to graph online
python graph visualization
how to plot a graph in python
how to plot a graph in python using matplotlib
how to plot a graph in python from csv file
how to plot a graph in python bar graph
how to plot a graph in python using matplotlib
how to plot a graph in python w3schools

Post Views: 507
Python Interview Question Tags:bestway to draw a graph in python, create line graph using python, graphs in python, how to graph in python, how to make a graph python, how to make a plot in python., how to make line graph in python, line graph using python, plot a graph using python, plot a line graph using matplotlib, plot a line graph using matplotlib python, Python, python matplotlib, python matplotlib tutorial, python plotting, python programming, Python Tutorial

Post navigation

Previous Post: SQL AND Condition in SQL Queries
Next Post: SQL OR Condition in SQL Queries

More Related Articles

How to Convert Text to Speech in Python How to Convert Text to Speech in Python Python Interview Question
How to Compare Two Lists in Python: Methods and Examples - How to Compare Two Lists in Python How to Compare Two Lists in Python: Methods and Examples Python Interview Question
How to Remove an Element from a List in Python How to Remove an Element from a List in Python Python Interview Question

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may also like

  1. How to Install Python on Windows: A Step-by-Step Guide
  2. How to Run Python Program: A Comprehensive Guide for Python Programmers
  3. How to Append Elements to a List in Python
  4. How to Declare a Global Variable in Python
  5. How to Clear the Python Shell
  6. Insertion Sort in Python

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. Flipkart Clone using PHP And MYSQL Free Source Code
  5. News Portal Project in PHP and MySql Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Online Bike Rental Management System Using PHP and MySQL
  9. E learning Website in php with Free source code
  10. E-Commerce Website Project in Java Servlets (JSP)
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital
  • Job Portal Web Application in PHP MySQL
  • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
  • Online Job Portal System in JSP Servlet MySQL

Most Viewed Posts

  • Top Large Language Models in 2025 (8,612)
  • Online Shopping System using PHP, MySQL with Free Source Code (5,211)
  • login form in php and mysql , Step-by-Step with Free Source Code (4,866)

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme