/  Top Machine learning interview questions and answers   /  What do you mean by Matplotlib?
Matplotlib (i2tutorials)

What do you mean by Matplotlib?

Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.

One of the greatest benefits of visualization is that it allows us visual access to huge amounts of data in easily digestible visuals. Matplotlib consists of several plots like line, bar, scatter, histogram etc.

Line plot :

Matplotlib (i2tutorials)

# importing matplotlib module 

from matplotlib import pyplot as plt

  

# x-axis values

x = [5, 2, 9, 4, 7]

  

# Y-axis values

y = [10, 5, 8, 4, 2]

  

# Function to plot

plt.plot(x,y)

  

# function to show the plot

plt.show()

Bar plot :

Matplotlib 1 (i2tutorials)

# importing matplotlib module 

from matplotlib import pyplot as plt

  

# x-axis values

x = [5, 2, 9, 4, 7]

  

# Y-axis values

y = [10, 5, 8, 4, 2]

  

# Function to plot the bar

plt.bar(x,y)

  

# function to show the plot

plt.show()

Histogram :Matplotlib2 (i2tutorials)

# importing matplotlib module 

from matplotlib import pyplot as plt

  

# Y-axis values

y = [10, 5, 8, 4, 2]

  

# Function to plot histogram

plt.hist(y)

  

# Function to show the plot

plt.show()

Scatter Plot :

Matplotlib 3 (i2tutorials)

# importing matplotlib module 

from matplotlib import pyplot as plt

  

# x-axis values

x = [5, 2, 9, 4, 7]

  

# Y-axis values

y = [10, 5, 8, 4, 2]

  

# Function to plot scatter

plt.scatter(x, y)

  

# function to show the plot

plt.show() 

Leave a comment