import matplotlib.pyplot as plt

%matplotlib inline
import numpy as np
x = np.arange(0,10)
y=np.arange(11,21)
a=np.arange(40,50)
b=np.arange(50,60)

Scatter plot

plt.scatter(x,y,c='g')  # c= color
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.title('Graph in 2D')
plt.savefig('g1.png')
plt.show()

plt plot

plt.plot(x,y)
[<matplotlib.lines.Line2D at 0x20b5b3bef48>]
y=x*x
plt.plot(x,y)
[<matplotlib.lines.Line2D at 0x20b5b4228c8>]
plt.plot(x,y,'r')
[<matplotlib.lines.Line2D at 0x20b5b447d08>]
plt.plot(x,y,'r--')
[<matplotlib.lines.Line2D at 0x20b5b4ef748>]
plt.plot(x,y,'r*-')
[<matplotlib.lines.Line2D at 0x20b5b562fc8>]

Subplots

plt.subplot(2,2,1) # 2 rows 2 cols 1 position
plt.plot(x,y,'r')
plt.subplot(2,2,2)
plt.plot(x,y,'g')
plt.subplot(2,2,3)
plt.plot(x,y,'b')
[<matplotlib.lines.Line2D at 0x20b5b61f088>]
 
np.pi
3.141592653589793
x = np.arange(0,4*np.pi,0.1)
y=np.sin(x)

plt.title("sine wave form")

plt.plot(x,y)
plt.show()
x=np.arange(0,5*np.pi,0.1)

y_sin = np.sin(x)
y_cos = np.cos(x)

plt.subplot(2,1,1)
plt.plot(x,y_sin,'r--')
plt.title("sine graph")

plt.subplot(2,1,2)
plt.plot(x,y_cos,'g--')
plt.title("cosine graph")

plt.show()

Bar plot

x= [2,8,10]
y = [11,16,18]

x2 = [3,9,11]
y2 = [4,7,9]

plt.bar(x,y)
plt.bar(x2,y2,color ='g')

plt.title('Bar graph')
plt.ylabel( 'Yaxis')
plt.xlabel( 'Xaxis')

plt.show()

Histograms

 a = np.array([1,2,3,4,5,5,6,67,7,8,8,9])  # y axis == bins - desity or count

plt.hist(a)
plt.title('histogram')
plt.show()

Box plot

data = [np.random.normal(0,std,100) for std in range(1,4)] # selecting a normal distribution b/w low=0, to std, step=100

# rectangular box plot
plt.boxplot(data, vert=True, patch_artist= True)
{'whiskers': [<matplotlib.lines.Line2D at 0x20b5bb46688>,
  <matplotlib.lines.Line2D at 0x20b5bb46f08>,
  <matplotlib.lines.Line2D at 0x20b5bb55d08>,
  <matplotlib.lines.Line2D at 0x20b5bb55e88>,
  <matplotlib.lines.Line2D at 0x20b5bb6b188>,
  <matplotlib.lines.Line2D at 0x20b5bb6ba08>],
 'caps': [<matplotlib.lines.Line2D at 0x20b5bb4b8c8>,
  <matplotlib.lines.Line2D at 0x20b5bb4bf48>,
  <matplotlib.lines.Line2D at 0x20b5bb5bdc8>,
  <matplotlib.lines.Line2D at 0x20b5bb5bec8>,
  <matplotlib.lines.Line2D at 0x20b5bb6bb88>,
  <matplotlib.lines.Line2D at 0x20b5bb71a08>],
 'boxes': [<matplotlib.patches.PathPatch at 0x20b5bb46048>,
  <matplotlib.patches.PathPatch at 0x20b5bb50fc8>,
  <matplotlib.patches.PathPatch at 0x20b5bb65ac8>],
 'medians': [<matplotlib.lines.Line2D at 0x20b5bb4bfc8>,
  <matplotlib.lines.Line2D at 0x20b5bb5fd08>,
  <matplotlib.lines.Line2D at 0x20b5bb71b88>],
 'fliers': [<matplotlib.lines.Line2D at 0x20b5bb50f08>,
  <matplotlib.lines.Line2D at 0x20b5bb5fe08>,
  <matplotlib.lines.Line2D at 0x20b5bb76a08>],
 'means': []}
data
[array([-0.7784494 , -0.30130908,  0.54002525, -0.51800759,  0.01819769,
        -0.83990426, -0.28781469,  0.04318482,  1.23528389,  2.1785494 ,
        -2.0737086 ,  1.0928547 , -0.0187436 ,  1.26047616, -0.22879622,
         0.7987299 , -1.32200805,  1.5095032 , -0.90634209, -0.88452427,
         0.21450132, -0.33105648, -0.89893418,  0.2640048 ,  0.18846496,
        -0.13365763, -0.56769452,  1.70685974,  2.50448167, -0.71739823,
        -2.15135456, -0.79866835,  0.01126657,  0.03509671,  0.70977944,
        -0.48825295, -0.51388798,  0.03850738, -0.11959896, -1.44425172,
        -0.48869629,  1.99891486, -0.79457436,  0.82734671, -0.21331385,
        -1.01447424, -1.62881497,  1.55287689, -0.76185124, -1.33031956,
        -0.24552639,  0.07408732, -2.05106282,  1.08293709, -0.39720809,
        -0.37170031, -0.78308727,  0.94345425, -1.61168896,  0.75191668,
        -0.19178661,  0.35292808, -0.32761845, -0.12057788, -0.90665516,
         0.61673275,  0.3552815 , -0.75085115,  0.95438335, -0.4752099 ,
        -1.22754795,  0.90739187,  0.98549253,  1.17860435, -0.47033725,
        -1.11863367, -2.1007785 , -1.28848407, -0.97587155, -1.50746364,
         0.15689869, -1.29434923,  0.95408283,  0.38562582,  1.09328084,
        -0.83567472,  1.46300781,  0.21707649,  1.04889211,  0.13129867,
         0.78442675,  0.21995366,  1.63712729,  1.50326651,  0.28453443,
        -0.2031552 , -0.28490282,  1.33678566,  2.37008989,  0.79503051]),
 array([ 1.23556973, -0.02072204, -1.12229404, -2.96722053, -1.30085601,
        -2.60421508,  1.24700109, -0.31148209, -2.52475577, -3.79873713,
        -0.5184776 , -1.40388223, -0.76082764,  1.21536502, -0.98142646,
         0.43235375,  2.01282379, -0.21453285,  3.61200475,  1.8287454 ,
        -2.37699005, -4.43876649, -1.5534308 ,  0.19087839,  0.63776082,
        -3.89796591, -0.77253082,  0.15942456,  1.50682854, -2.13153439,
        -0.03070496, -0.87138476, -3.60486968, -3.73673651,  1.36459964,
        -0.57526159,  1.74855   , -1.59916748, -2.53317411,  0.34688596,
        -0.39179164,  3.50326963, -2.16398775,  1.6853139 ,  0.93583756,
        -3.19704488,  2.29302575,  0.1907704 ,  1.65541487, -1.30203682,
         2.56856035,  0.0327959 ,  4.19304044, -1.00926479, -2.24279789,
        -0.69572595, -1.76483291,  3.0767504 , -2.20523853,  3.85941305,
         0.02224512,  0.51100795, -0.64877433, -0.97541769, -0.55332363,
         0.68110681,  1.04656981, -1.66401884, -2.22326276,  2.5260883 ,
         1.23117647, -0.60578903,  0.08622414,  1.41381078, -2.7653705 ,
        -0.97335699,  2.92662744, -0.83610816,  2.29915347,  0.01851729,
        -1.31768037, -1.48470864,  1.02320517,  0.44434635, -3.43562133,
        -0.4494547 ,  0.08147359,  3.30459418,  1.80139721, -1.308831  ,
        -0.99884576, -1.46526386, -0.54199541,  1.12811024,  2.97529432,
         1.64583481, -0.78990555, -0.74874302, -4.4103771 , -2.48981923]),
 array([ 3.95391703e+00, -1.07121577e+00, -3.84668853e+00,  6.77840007e+00,
        -2.19381045e+00,  7.10352670e-01,  6.73618307e-01,  1.37069922e+00,
        -3.81843396e+00,  1.26967121e+00, -2.22084017e+00, -3.53653835e+00,
         9.12261523e-01,  3.46900445e+00,  5.60861189e-01,  1.81888792e+00,
         7.13406114e-01, -3.34833646e+00,  1.39887349e+00, -1.53083906e+00,
         3.99241572e+00, -1.95620365e+00, -1.32736259e+00,  1.45314767e+00,
         1.86896524e+00,  1.41268309e+00, -2.04054499e+00, -3.22104097e+00,
        -3.38356292e+00, -1.07288730e+00, -2.13342416e+00, -1.17784314e+00,
        -5.50678185e-01, -2.93018741e+00,  6.09593785e+00,  3.56688350e-01,
        -2.74400006e+00,  1.41395686e+00, -1.06679209e+00,  3.99608167e+00,
        -1.63810367e+00,  3.26794993e+00, -2.17703756e+00,  5.76026096e+00,
        -3.16019468e+00, -2.04739358e+00, -9.21248072e-01, -1.17306562e+00,
        -1.40941302e+00, -3.39076210e+00,  8.42848917e+00, -2.23424984e+00,
         1.51486619e+00,  3.39342705e+00, -3.71272706e+00,  9.32418444e+00,
        -2.89173783e+00, -7.17807468e-01,  6.45628003e+00,  2.46759215e+00,
        -5.40677123e-01,  1.03397626e+00, -4.61687260e-01,  2.28964222e+00,
        -1.45379187e+00,  1.09286059e+00,  1.66547924e+00,  2.60394771e+00,
         3.59662329e-02, -1.58705864e+00, -2.26368232e+00,  2.50848563e+00,
        -1.72671381e+00, -3.19559078e+00, -9.92987939e-01,  8.91871959e-01,
         1.03963870e+00, -4.01271402e-01,  3.12010149e+00, -1.35404888e+00,
         2.93841033e+00, -9.41879808e-02,  5.56786269e-01, -9.35989605e-01,
         1.10483247e+00, -1.21961918e+00, -4.03470597e-01, -1.41275722e-01,
         2.15839643e-01, -2.90275833e+00,  6.03367683e+00,  4.09121350e+00,
         3.09437534e+00, -2.16658125e-03,  2.75046954e+00,  8.71768377e-01,
        -2.33004375e+00, -8.64465990e-03,  2.06668848e+00,  5.57575505e-01])]

Pi chart

labels = 'python','c++', 'ruby', 'java'
sizes = [215,130,245,210]
colors = ['gold', 'yellowgreen','lightcoral', 'lightskyblue']
explode = (0.1,0,0,0) #explode 1st slice

#plot
plt.pie(sizes,explode=explode,labels=labels,colors=colors, autopct='%1.1f%%',shadow=True)

plt.axis('equal')
plt.show()