Data Visualization using Matplotlib

Bar graph in Jupyter Notebook

Bar Graph represents data using rectangular bars of variable length and the length of bar corresponds the value it represents. It is effective for comparing categories or discrete data points.

Follow the below steps to use bar graph in you Jupyter Notebook:

  • import the matplotlib module
  • Take the x-axis input in an array.
  • Take the y-axis input in an array.
  • Plot the Bar Graph using bar() functions. We can set other options like color, width to customize the bar graph see the below example
  • Set the title of your graph by using title() function
  • Show the graph using show() method

Example:

Python3




import matplotlib.pyplot as plt
x = [10, 20, 30, 40, 50, 60]
y = [13, 45, 23, 34, 96, 76]
plt.title('Bar Graph')
plt.bar(x, y, color='dodgerblue', width=5)
plt.show()


Output:

Bar Graph

Pie Chart in Jupyter Notebook

A pie chart displays data as circular graph divided into slices, and each slice represents a proportion or percentage of the whole.

Follow the below steps to use pie chart in you Jupyter Notebook:

  • import the matplotlib module
  • Take the labels of your data in an array, e.g label = [‘apples’ , ‘bananna’, ‘orange’]
  • Take the values in an array, e.g. values = [13, 45, 23, 34, 96, 76]
  • Plot the Pie Chart using pie() method. We can set other options like explode, autopct, pctdistance, startangle to customize the pie chart
  • Set the title of your graph by using title() function
  • Show the graph using show() method.

Example:

Python3




import matplotlib.pyplot as plt
x = [35, 20, 30, 40, 50, 30]
y = ['Apple', 'Bananna', 'Grapes', 'Orange', 'PineApple', 'Dragon Fruit']
plt.title('Pie Chart')
plt.pie(x, labels=y)
plt.show()


Output:

Data Visualization in jupyter notebook

In this article, we will learn how to visualize data in Jupyter Notebook there are different libraries available in Python for data visualization like Matplotlib, seaborn, Plotly, GGPlot, Bokeh, etc. But in this article, we will use different libraries like Matplotlib, searborn, and Plotly which are widely used for data visualization. We will generate different graphs and plots in Jupyter Notebook using these libraries such as bar graphs, pie charts, line charts, scatter graphs, histograms, and box plots. We will also discuss how to install these libraries and use examples to understand each graph.

Jupyter Notebook

The Jupyter Notebook is the original web application for creating and sharing computational documents that contain live code, equations, visualizations, and narrative text. It offers a simple, streamlined, document-centric experience. Jupyter has support for over 40 different programming languages and Python is one of them.

Prerequisites

In this article, we will use different libraries to create graphs and plots and you have to install the library to function the below example you can use the following code snippetes to install the dependencies.

Install matplotlib

pip install matplotlib

Install Seaborn

pip install seaborn

Install Plotly

pip install plotly

Similar Reads

Data Visualization

Data visualization is the graphical representation of information and data in a pictorial or graphical format like line chart, bar graph, pie chart etc. Data visualization helps to gain insights from the data to understand the underlying trends in the data helps the organization to make data-driven decisions. Reasons why data visulization is important:...

Data Visualization using Matplotlib

Bar graph in Jupyter Notebook...

Data Visualization using Seaborn

...

Data Visualization using Plotly

...

Contact Us