Matplotlib (Basics/)

Saksham Awasthi
3 min readJul 27, 2021

If you are also facing issue in using this library in your journey to ML. Let me help you a lil bit ….💢

If (!matplotlib)
open terminal -> -m pip install -U pip

else
Now, all set.

Matplotlib is a library used for creating graphs or a diagram of axes i.e, dealing with two of the axes.
The simplest way to implement a single axes is using pyplot.subplot (This may be called the subset of the mat.)

For implementing this library in our program we have to first import matplotlib as :

import matplotlib.plyplot as plt;
import numpy as np

Now we know that the output would be in the form of a figure, So we would write a line of code saying :

fig , a = plt.subplots() ##here we have created or told the machine that a is a type of figure and will be using the subplot function for making single axes figure
a.

a.plot([0,4,8],[0,4,0])# here we have created a triangle and plot fun(x) takes the axes to be implemented on the fig a that is subplotted as plt.

The output would look like this.

Now we can play with this subplot function as a toy such as :)

fig = plt.subplots()# this is the fig with no axes

2nd method :: fig , ax = plt.subplots()# here it is having a single axes with no further demo

3rd One :: fig, axes = plt.subplots(4,5)# this will creates the grid for each as 1st with the rows and second with the columns

A given figure can contain many Axes, but a given Axes object can only be in one Figure. The Axes contains two (or three in the case of 3D) Axis objects (be aware of the difference between Axes and Axis).

  • Explicitly create figures and axes, and call methods on them (the “object-oriented (OO) style”).
  • Rely on pyplot to automatically create and manage the figures and axes, and use pyplot functions for plotting.

--

--