Matplotlib is an “extensive library for creating static, animated, and interactive visualizations in Python.” Most of the Matplotlib utilities lie under the pyplot submodule and are usually imported under the plt alias:
Example
Use the read_csv() function of the DataFrame data structure in Pandas.
data = pd.read_csv('data.csv', skiprows=4)
data
You can use the read_csv() function, skip the first four rows, and then display the remaining ones.
Run the cell and see the output. It will show the first 30 rows and the last 30 if so many exist. In our data file, there are more than 29,000 rows. That is why we can see the first and last 30 rows.
Import Matplotlib
We can import the Matplotlib library using the following code. Next, write the following code inside the next Jupyter Notebook cell.
import matplotlib.pyplot as plt
%matplotlib inline
Now, hit Ctrl + Enter, which will import the Library.
An iPython kernel works seamlessly with Matplotlib.pyplot Library.
You can see in the above code that we have used the %matplotlib inline magic command, which means it will show different charts inside the Jupyter Notebook.
Plot Types
There is a kind of Plot type which are following.

plot(kind=line): It is best when we need to track the changes over some time.

plot(kind=bar): Bar graphs are best for comparing the groups.

plot(kind=pie): Best for reaching the parts of a whole system.
Now let’s take an example of a onebyone chart in Jupyter Notebook.
Let’s plot a graph of sports that participate in the Olympics Edition 2008.
We have already imported the matplotlib.pyplot Library in the Notebook, now we will use that to plot the graph of different sports.
Plotting a Line Chart
We will display the line chart. So let’s add the following code to the Jupyter Notebook.
filteredData = data[data.Edition == 2008]
filteredData.Sport.value_counts().plot()
In the above code, first, we have the data for the Olympics 2008 edition; then, we have to count the number of sports the Olympics has and plot the line graph based on that data.
By default, the plot() function gives us the line chart.
Plotting a BarChart
We can also display the bar chart instead of the line chart. We must pass a parameter kind and value to the bar, showing the bar chart.
filteredData = data[data.Edition == 2008]
filteredData.head()
filteredData.Sport.value_counts().plot(kind='bar')
Here, we have used the head() function to display the first five rows and plot the bar charts based on the sports count held in the 2008 Olympics.
Output
The above bar chart is the Vertical Bar Chart.
We can also get the Horizontal plot using the following code.
filteredData.Sport.value_counts().plot(kind='barh')
We passed the kind=’barh’ parameter, giving us the following result.
Plotting a Pie Chart
We can also display the pie chart instead of the bar chart. We must pass a parameter kind and value to the pie, showing the bar chart. See the following example. Write the following code in the cell.
filteredData = data[data.Edition == 2008]
filteredData.head()
filteredData.Sport.value_counts().plot(kind='pie')
Output
So, we have learned all kinds of charts using the Realtime example in Python Jupyter Notebook.
Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both frontend and backend development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.