0% found this document useful (0 votes)
8 views

Matplotlib

The document discusses various types of plots that can be created using Matplotlib like line plot, scatter plot, histogram, pie chart, bar plot etc. It includes code examples to create these plots and customize aspects like colors, labels, legends etc.

Uploaded by

patelhemv1143
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Matplotlib

The document discusses various types of plots that can be created using Matplotlib like line plot, scatter plot, histogram, pie chart, bar plot etc. It includes code examples to create these plots and customize aspects like colors, labels, legends etc.

Uploaded by

patelhemv1143
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15


















Line Chart Histogram Scatter Plot 3D Plot Bar Chart Pie Chart










import matplotlib.pyplot as plt
%matplotlib inline
values = [5,8,9,4,1,6,7,2,3,8]
plt.plot(range(1,11),values)
plt.show()








import matplotlib.pyplot as plt
%matplotlib inline
values1 = [5,8,9,4,1,6,7,2,3,8]
values2 = [8,3,2,7,6,1,4,9,8,5]
plt.plot(range(1,11),values1)
plt.plot(range(1,11),values2)
plt.show()






import matplotlib.pyplot as plt
%matplotlib inline
values1 = [5,8,9,4,1,6,7,2,3,8]
values2 = [8,3,2,7,6,1,4,9,8,5]
plt.plot(range(1,11),values1)
plt.plot(range(1,11),values2)
#plt.show()
plt.savefig('SaveToPath.png',format='png')








import matplotlib.pyplot as plt
%matplotlib notebook
values = [5,8,9,4,1,6,7,2,3,8]
ax = plt.axes()
ax.set_xlim([0,50])
ax.set_ylim([-10,10])
ax.set_xticks([0,5,10,15,20,25,30,35,40,45,50])
ax.set_yticks([-10,-8,-6,-4,-2,0,2,4,6,8,10])
ax.grid()
plt.plot(range(1,11),values)




o
o
o
o


 
import matplotlib.pyplot as plt
%matplotlib inline
values1 = [5,8,9,4,1,6,7,2,3,8]
values2 = [8,3,2,7,6,1,4,9,8,5]
plt.plot(range(1,11),values1,c='r',lw=1,ls='--',marker='>')
plt.plot(range(1,11),values2,c='b',lw=2,ls=':',marker='o')
plt.show()





















     
     
     
     
  

   
   
   
  

 
 




o

o


import matplotlib.pyplot as plt
%matplotlib inline
values1 = [5,8,9,4,1,6,7,2,3,8]
values2 = [8,3,2,7,6,1,4,9,8,5]
plt.plot(range(1,11),values1)
plt.plot(range(1,11),values2)
plt.xlabel('Roll No')
plt.ylabel('CPI')
plt.annotate(xy=[5,1],s='Lowest CPI')
plt.legend(['CX','CY'],loc=4)
plt.show()













import matplotlib.pyplot as plt

 %matplotlib notebook
 values = [305,201,805,35,436]
 l = ['Food','Travel','Accomodation','Misc','Shoping']
 c = ['b','g','r','c','m']
 e = [0,0.2,0,0,0]
 plt.pie(values,colors=c,labels=l,explode=e)

 plt.show()




import matplotlib.pyplot as plt

 %matplotlib notebook
 x = [1,2,3,4,5]
 y = [5.9,6.2,3.2,8.9,9.7]
 l = ['1st','2nd','3rd','4th','5th']
 c = ['b','g','r','c','m']
 w = [0.5,0.6,0.3,0.8,0.9]


plt.title('Sem wise spi')
 plt.bar(x,y,color=c,label=l,width=w)
 plt.show()



import matplotlib.pyplot as plt

 import numpy as np
 %matplotlib notebook
 cpis = np.random.randint(0,10,100)
 plt.hist(cpis,bins=10, histtype='stepfilled',align='mid',label='CPI
 Hist')
 plt.legend()

 plt.show()




import pandas as pd

 import matplotlib.pyplot as plt
 %matplotlib inline
 timetaken = pd.Series([50,45,52,63,70,21,56,68,54,57,35,62,65,92,32])
 plt.boxplot(timetaken)

import matplotlib.pyplot as plt


import pandas as pd
%matplotlib inline
df = pd.read_csv('insurance.csv')
plt.scatter(df['bmi'], df['charges'])
plt.show()



import matplotlib.pyplot as plt

 import pandas as pd
 %matplotlib inline
 df = pd.read_csv('insurance.csv')
 grouped = df.groupby(['smoker'])
 for key, group in grouped:
 plt.scatter(group['bmi'], group['charges'], label='Smoke = '+key)

plt.legend()

 plt.show()



import pandas as pd

 import datetime as dt
 start_date = dt.datetime(2020,8,28)
 end_date = dt.datetime(2020,9,05)
 daterange = pd.date_range(start_date,end_date)
 print(daterange)

DatetimeIndex(['2020-08-28', '2020-08-29', '2020-08-30', '2020-08-31', '2020-09-01',


'2020-09-02', '2020-09-03', '2020-09-04', '2020-09-05'],
dtype='datetime64[ns]', freq='D')



































import networkx as nx
g = nx.Graph() # undirected graph
g.add_edge('rajkot','junagadh')
g.add_edge('junagadh','porbandar')
g.add_edge('rajkot','jamnagar')
g.add_edge('jamnagar','bhanvad')
g.add_edge('bhanvad','porbandar')
nx.draw(g,with_labels=True)


import networkx as nx
gD = nx.DiGraph() # directed graph
gD.add_edge('Modi','Arjun')
gD.add_edge('Modi','GambhavaSir')
gD.add_edge('GambhavaSir','Modi')
nx.draw(gD, with_labels=True)






o


o


o



o
o


o
o

You might also like