Professional Documents
Culture Documents
Basic Components of Graph: Matplotlib Introduction
Basic Components of Graph: Matplotlib Introduction
Basic Components of Graph: Matplotlib Introduction
1. Figure or chart area: The entire area covered by the graph is known as a
figure. It can be also considered as a canvas or chart area also.
2. Axis: These are the number of lines generated on the plot. Basically, there are
two axis X and Y-axis.
3. Artist: The components like text objects, Line 2D objects, collection objects, etc.
4. Titles: There are few titles involved with your charts such as Chart Title, Axis
title, etc.
5. Legends: Legends are the information that represents data with lines or dots.
matplotlib Introduction
Python supports a variety of packages to handle data. Matplotlib is also one of the most
important packages out of them. It is a low-level library integrated with Matlab like
interface offers few lines of code and draw graphs or charts. It has modules such as a
pyplot to draw and create graphs.
Steps – how to create graphs using matplotlib
The following are basic steps to create a chart.
Step 1 Installation of matplotlib
Install matplotlib by following these simple steps:
Step 1: Open cmd from the start menu
Step 2: Type pip install matplotlib
• Line plot
• Bar graph
• Histogram
• Pie chart
• Scatter chart
Output:
In the above code, 3 subject marks are plotted on the figure. The navigation toolbar
helps to navigate through the graph. Now observe the following code for plotting
multiple lines on the graph.
import matplotlib.pyplot as mpp
o=[5,10,15,20]
r_india=[30,80,120,200]
mpp.plot(o,r_india,'Red')
r_aust=[25,85,100,186]
mpp.plot(o,r_aust,'Yellow')
mpp.xlabel('Runs')
mpp.ylabel('Overs')
mpp.title('Match Summary')
mpp.show()
Output: