Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data preprocessing
  • Data Manipulation
  • Data Analysis using Pandas
  • EDA
  • Pandas Exercise
  • Pandas AI
  • Numpy
  • Matplotlib
  • Plotly
  • Data Analysis
  • Machine Learning
  • Data science
Open In App
Next Article:
Plotly for Data Visualization in Python
Next article icon

Data Visualization with Pandas

Last Updated : 17 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Pandas allows to create various graphs directly from your data using built-in functions. This tutorial covers Pandas capabilities for visualizing data with line plots, area charts, bar plots, and more.

Data-Visualization-with-Pandas

Introducing Pandas for Data Visualization

Pandas is a powerful open-source data analysis and manipulation library for Python. The library is particularly well-suited for handling labeled data such as tables with rows and columns.

Key Features for Data Visualization with Pandas:

Pandas offers several features that make it a great choice for data visualization:

  • Variety of Plot Types: Pandas supports various plot types including line plots, bar plots, histograms, box plots, and scatter plots.
  • Customization: Users can customize plots by adding titles, labels, and styling enhancing the readability of the visualizations.
  • Handling of Missing Data: Pandas efficiently handles missing data ensuring that visualizations accurately represent the dataset without errors.
  • Integration with Matplotlib: Pandas integrates with Matplotlib that allow users to create a wide range of static, animated, and interactive plots.

Installation of Pandas

To get started you need to install Pandas using pip:

pip install pandas

Importing necessary libraries and data files

Once Pandas is installed, import the required libraries and load your data Sample CSV files df1 and df2 used in this tutorial can be downloaded from here.

Python
import numpy as np import pandas as pd  df1 = pd.read_csv('df1', index_col=0) df2 = pd.read_csv('df2') 

Pandas DataFrame Plots

Pandas provides several built-in plotting functions to create various types of charts mainly focused on statistical data. These plots help visualize trends, distributions, and relationships within the data. Let's go through them one by one:

1. Line Plots using Pandas DataFrame

A Line plot is a graph that shows the frequency of data along a number line. It is best to use a line plot when the data is time series. It can be created using Dataframe.plot() function.

Python
df2.plot() 


We have got the well-versed line plot for df without specifying any type of features in the .plot() function.

2. Area Plots using Pandas DataFrame

Area plot shows data with a line and fills the space below the line with color. It helps see how things change over time. we can plot it using DataFrame.plot.area() function.

Python
df2.plot.area(alpha=0.4) 


3. Bar Plots using Pandas DataFrame

A bar chart presents categorical data with rectangular bars with heights or lengths proportional to the values that they represent. The bars can be plotted vertically or horizontally with DataFrame.plot.bar() function.


Python
df2.plot.bar() 


4. Histogram Plot using Pandas DataFrame

Histograms help visualize the distribution of data by grouping values into bins. Pandas use DataFrame.plot.hist() function to plot histogram.

Python
df1['A'].plot.hist(bins=50) 

5. Scatter Plot using Pandas DataFrame

Scatter plots are used when you want to show the relationship between two variables. They are also called correlation and can be created using DataFrame.plot.scatter() function.

Python
df1.plot.scatter(x ='A', y ='B') 


6. Box Plots using Pandas DataFrame

A box plot displays the distribution of data, showing the median, quartiles, and outliers. we can use DataFrame.plot.box() function or DataFrame.boxplot() to create it.

Python
df2.plot.box()  


7. Hexagonal Bin Plots using Pandas DataFrame

Hexagonal binning helps manage dense datasets by using hexagons instead of individual points. It’s useful for visualizing large datasets where points may overlap. Let's create the hexagonal bin plot.

Python
df.plot.hexbin(x ='a', y ='b', gridsize = 25, cmap ='Oranges') 


8. Kernel Density Estimation plot (KDE) using Pandas DataFrame

KDE (Kernel Density Estimation) creates a smooth curve to show the shape of data by using the df.plot.kde() function. It's useful for visualizing data patterns and simulating new data based on real examples. 

Python
df2['a'].plot.kde() 


Customizing Plots

Pandas allows you to customize your plots in many ways. You can change things like colors, titles, labels, and more. Here are some common customizations.

1. Adding a Title, Axis Labels, and Gridlines

You can customize the plot by adding a title and labels for the x and y axes. You can also enable gridlines to make the plot easier to read:

Python
df.plot(title='Customized Line Plot', xlabel='Index', ylabel='Values', grid=True) 


2. Line Plot with Different Line Styles

If you want to differentiate between the two lines visually you can change the line style (e.g., solid line, dashed line) with the help of pandas.

Python
df.plot(style=['-', '--', '-.', ':'], title='Line Plot with Different Styles', xlabel='Index', ylabel='Values', grid=True) 


3. Adjusting the Plot Size

Change the size of the plot to better fit the presentation or analysis context You can change it by using the figsize parameter:

Python
df.plot(figsize=(12, 6), title='Line Plot with Adjusted Size', xlabel='Index', ylabel='Values', grid=True) 


4. Stacked Bar Plot

A stacked bar plot can be created by setting stacked=True. It helps you visualize the cumulative value for each index.

Python
df.plot.bar(stacked=True, figsize=(10, 6), title='Stacked Bar Plot', xlabel='Index', ylabel='Values', grid=True) 

In this tutorial we explored how to visualize data using Pandas and customization without needing any additional visualization libraries. With Pandas' built-in plotting functions you can easily generate a variety of charts and graphs to gain insights into your data.


Next Article
Plotly for Data Visualization in Python

T

tyagikartik4282
Improve
Article Tags :
  • Data Visualization
  • AI-ML-DS
  • Python-pandas
  • AI-ML-DS With Python
  • Python Data Visualization

Similar Reads

    Python - Data visualization tutorial
    Data visualization is a crucial aspect of data analysis, helping to transform analyzed data into meaningful insights through graphical representations. This comprehensive tutorial will guide you through the fundamentals of data visualization using Python. We'll explore various libraries, including M
    7 min read
    What is Data Visualization and Why is It Important?
    Data visualization is the graphical representation of information and data. It uses visual elements like charts, graphs and maps to help convey complex information in a way that is easy to understand and interpret. By transforming large datasets into visuals, it allows decision-makers to spot trends
    5 min read
    Data Visualization using Matplotlib in Python
    Matplotlib is a widely-used Python library used for creating static, animated and interactive data visualizations. It is built on the top of NumPy and it can easily handles large datasets for creating various types of plots such as line charts, bar charts, scatter plots, etc. These visualizations he
    10 min read
    Data Visualization with Seaborn - Python
    Seaborn is a widely used Python library used for creating statistical data visualizations. It is built on the top of Matplotlib and designed to work with Pandas, it helps in the process of making complex plots with fewer lines of code. It specializes in visualizing data distributions, relationships
    9 min read
    Data Visualization with Pandas
    Pandas allows to create various graphs directly from your data using built-in functions. This tutorial covers Pandas capabilities for visualizing data with line plots, area charts, bar plots, and more.Introducing Pandas for Data VisualizationPandas is a powerful open-source data analysis and manipul
    5 min read
    Plotly for Data Visualization in Python
    Plotly is an open-source Python library designed to create interactive, visually appealing charts and graphs. It helps users to explore data through features like zooming, additional details and clicking for deeper insights. It handles the interactivity with JavaScript behind the scenes so that we c
    12 min read
    Data Visualization using Plotnine and ggplot2 in Python
    Plotnoine is a Python library that implements a grammar of graphics similar to ggplot2 in R. It allows users to build plots by defining data, aesthetics, and geometric objects. This approach provides a flexible and consistent method for creating a wide range of visualizations. It is built on the con
    7 min read
    Introduction to Altair in Python
    Altair is a statistical visualization library in Python. It is a declarative in nature and is based on Vega and Vega-Lite visualization grammars. It is fast becoming the first choice of people looking for a quick and efficient way to visualize datasets. If you have used imperative visualization libr
    5 min read
    Python - Data visualization using Bokeh
    Bokeh is a data visualization library in Python that provides high-performance interactive charts and plots. Bokeh output can be obtained in various mediums like notebook, html and server. It is possible to embed bokeh plots in Django and flask apps. Bokeh provides two visualization interfaces to us
    4 min read
    Pygal Introduction
    Python has become one of the most popular programming languages for data science because of its vast collection of libraries. In data science, data visualization plays a crucial role that helps us to make it easier to identify trends, patterns, and outliers in large data sets. Pygal is best suited f
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences