Open In App

Plot Data from Excel File in Matplotlib – Python

Last Updated : 28 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. It is a plotting library for the Python programming language and its numerical mathematics extension NumPy. In this article, we will learn how to plot data from an excel file in Matplotlib.

If you had not installed the Matplotlib and Pandas library you can install them using the pip command as follows:

pip install matplotlib
pip install pandas

Excel Data Used

You can download the above excel sheet from here.

 

Plot Data from an Excel File in Matplotlib

Here, we can plot any graph from the excel file data by following 4 simple steps as shown in the example.

Example 1

Import Matplotlib and Pandas module, and read the excel file using the Pandas read_excel() method. After reading data for the x-axis and y-axis from the excel file. Plot the graph using the Matplotlib library. Here, we are plotting a bar graph hence using the bar() method and the show() method to display the graph.

Python3




import matplotlib.pyplot as plt
import pandas as pd
file = pd.read_excel('data.xlsx')
x_axis = file['X values']
y_axis = file['Y values']
plt.bar(x_axis, y_axis, width=5)
plt.xlabel("X-Axis")
plt.ylabel("Y-Axis")
plt.show()


Output:

Plot Data from an Excel File in Matplotlib

 

Example 2

Now, we can plot other graphs and charts by using data from an excel file. Let’s plot a pie chart from the excel file which we used earlier.

Python3




import matplotlib.pyplot as plt
import pandas as pd
file = pd.read_excel('data.xlsx')
plt.pie(file['Value'],labels=file['Label'])
plt.show()


Output:

Plot Data from an Excel File in Matplotlib

 



Similar Reads

Plot 2D data on 3D plot in Python
In this article, we will be learning about how to plot 2D data on 3D plot in Python. We will be demonstrating two methods in order to learn the concept. The first method will be using Matplotlib.pyplot.gca() function which is a pyplot module of the matplotlib library. But before that, we need to configure where are we going to create our project an
4 min read
How to Save a Plot to a File Using Matplotlib?
Matplotlib is a widely used Python library to plot graphs, plots, charts, etc. show() method is used to display graphs as output, but don’t save it in any file. In this article, we will see how to save a Matplotlib plot as an image file. Save a plot in MatplotlibBelow are the ways by which we can save a plot to a file using Matplotlib in Python: Us
3 min read
Create a GUI to convert CSV file into excel file using Python
Prerequisites: Python GUI – tkinter, Read csv using pandas CSV file is a Comma Separated Value file that uses a comma to separate values. It is basically used for exchanging data between different applications. In this, individual rows are separated by a newline. Fields of data in each row are delimited with a comma. Modules Needed Pandas: Python i
3 min read
How to convert PDF file to Excel file using Python?
In this article, we will see how to convert a PDF to Excel or CSV File Using Python. It can be done with various methods, here are we are going to use some methods. Method 1: Using pdftables_api Here will use the pdftables_api Module for converting the PDF file into any other format. It's a simple web-based API, so can be called from any programmin
2 min read
How to Plot Histogram from List of Data in Matplotlib?
In this article, we are going to see how to Plot a Histogram from a List of Data in Matplotlib in Python. The histogram helps us to plot bar-graph with specified bins and can be created using the hist() function. Syntax: hist( dataVariable, bins=x, edgecolor='anyColor' ) Parameters: dataVariable- Any variable that holds a set of data. It can be a l
3 min read
PyQtGraph - Getting Plot Item from Plot Window
In this article we will see how we can get the plot item of plot window in the PyQtGraph module. PyQtGraph is a graphics and user interface library for Python that provides functionality commonly required in designing and science applications. Its primary goals are to provide fast, interactive graphics for displaying data (plots, video, etc.) and s
2 min read
Time Series Plot or Line plot with Pandas
Prerequisite: Create a Pandas DataFrame from Lists Pandas is an open-source library used for data manipulation and analysis in Python. It is a fast and powerful tool that offers data structures and operations to manipulate numerical tables and time series. Examples of these data manipulation operations include merging, reshaping, selecting, data cl
6 min read
Pandas Scatter Plot – DataFrame.plot.scatter()
A Scatter plot is a type of data visualization technique that shows the relationship between two numerical variables. For plotting to scatter plot using pandas there is DataFrame class and this class has a member called plot. Calling the scatter() method on the plot member draws a plot between two variables or two columns of pandas DataFrame. Synta
2 min read
Pandas - Plot multiple time series DataFrame into a single plot
In this article, we are going to see how to plot multiple time series Dataframe into single plot. If there are multiple time series in a single DataFrame, you can still use the plot() method to plot a line chart of all the time series. To Plot multiple time series into a single plot first of all we have to ensure that indexes of all the DataFrames
4 min read
Matplotlib.axes.Axes.plot() in Python
Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. Example: import datetime import matplotlib.pyplot
2 min read
Practice Tags :