1. you want any doubt what to plot, you can go to matplotlib website > galleries, and then find the thing you want to plot, the img
  2. it will take you to the example page, and you will find the document and code there

Matplotlib-1

#import matplotlib.pyplot as plt 
import matplotlib as plt
import numpy as np 

#functional way
x = np.linspace(0 , 2, 110)
y = x**2
plt.plot(x, y,'r-')
plt.xlabel('Xlabel')
plt.ylabel('Ylabel')
plt.title('title')
plt.show()
#multi plot on same canvas
plt.subplot(1,2,1) #1 row and 2 column, isme se 1st one mai,... ye karo
plt.plot(x,y,'r')
plt.subplot(1,2,2)
plt.plot(y,x,'b')

#Object Oriented Method
fig = plt.figure()#this is the canvas
axes = fig.add_axes([0.1,0.1,0.8,0.8])#left bottom width and height
axes.plot(x,y)
axes.set_xlabel('x-label')
axes.set_ylabel('y-label')
axes.set_title('title')
#showing two plot in one image
fig = plt.figure()
axes1 = fig.add_axes([0.1,0.1,0.8,0.8])
axes2 = fig.add_axes([0.2,0.5,0.4,0.4])
axes1.plot(x,y)
axes2.plot(y,x)
axes1.set_title('axes one')

plt.tight_layout() # removing overlappign

Matplotlib-2

import matplotlib.pyplot as plt 
import numpy as np
x = np.linspace(0,100,101)
y = x**2
fig,axes = plt.subplots(nrows=1,ncols=2)
for axes_i in axes: # either i can iterate
    axes_i.plot(x,y)
axes[0].plot(x,y)#or i can use the indexing
axes[0].set_title('first')
axes[1].plot(y,x)
axes[1].set_title('second')
plt.tight_layout()

Figure Size and DPI

#import matplotlib.pyplot as plt 
import matplotlib as plt
import numpy as np 

fig = plt.figure(figsize=(8,3),dpi = 100)
ax = fig.add_axes([0,0,1,1])
ax.plot(x,y)

fig,axes = plt.subplots(nrows =2,ncols=1,figsize=(8,2))
axes[0].plot(x,y)
plt.tight_layout()
fig.savefig('mypic.png',dpi = 2000) #saving the img
# ax = fig.add_axes([0,0,1,1])
# ax.plot(x,y)

#legend
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
x = np.linspace(0,5,10)
y = x**2
ax.plot(x,x**2,label = 'x2')
ax.set_title('title')
ax.set_ylabel('y')
ax.set_xlabel('x')
ax.plot(x,x**3,label = 'x3')

#to defferentiate two plot, use legend
ax.legend(loc=0) # it uses the label that you provided #loc specify the location that you can find in the website or you can use (loc = (0.1,0.1))

Matplotlib-3: customisation

#import matplotlib.pyplot as plt 
import matplotlib as plt
import numpy as np 

Matplotlib-3

import matplotlib.pyplot as plt 
import numpy as np
x =np.linspace(0,5,11)
y = x**2
fig = plt.figure()
ax1 = fig.add_axes([0,0,1,1])
ax1.plot(x,y,color='#FF8C00',linewidth=3,alpha=0.5,linestyle='--',marker='1',markersize=20) #rgb hex code and other data or color name like, red, purple, black
#linewidth ->lw->second parameter
#linestyle ->ls->'-','--','-.',':','steps'
#marker -> 'o','1','+'
#markersize -> defines marker size
#markerfacecolor='yellow'
#markeredgewidth=3
#markeredgecolor='red'

ax1.set_xlim([0,1]) #limit the variables in x
ax1.set_ylim([0,1])

Exercise

#import matplotlib.pyplot as plt 
import matplotlib as plt
import numpy as np