Professional Documents
Culture Documents
Matplotlib
Matplotlib
LAXMAN CHAUDHARY
DATA HANDLING
BHURIGAUN BARDIYA
(matplotlib)
line plot
In [1]: import matplotlib.pyplot as plt
In [2]: days=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
In [3]: temperature=[27,26,25,24,29,30,25.5,17.98,20.43,19,30,27,24.79,26.76,
In [4]: plt.plot(days,temperature)
plt.title('ktm temperarture')
plt.xlabel('days')
plt.ylabel('temperature')
plt.show
In [5]: plt.axis([0,20,0,32])
plt.plot(days,temperature)
plt.title('ktm temperarture')
plt.xlabel('days')
plt.ylabel('temperature')
1 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
plt.show
Out[5]: <function matplotlib.pyplot.show(close=None, block=None)>
In [6]: plt.plot(days,temperature,color='r',marker='o')
plt.title('ktm temperarture')
plt.xlabel('days')
plt.ylabel('temperature')
plt.show
2 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [7]: plt.plot(days,temperature,color='r',marker='^')
plt.title('ktm temperarture')
plt.xlabel('days')
plt.ylabel('temperature')
plt.show
In [8]: plt.plot(days,temperature,color='r',marker='o',linestyle="--")
plt.title('ktm temperarture')
plt.xlabel('days')
plt.ylabel('temperature')
plt.show
3 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [9]: plt.plot(days,temperature,color='r',marker='o',linestyle="-.")
plt.title('ktm temperarture')
plt.xlabel('days')
plt.ylabel('temperature')
plt.show
In [10]: plt.plot(days,temperature,color='r',marker='o',linestyle=":")
plt.title('ktm temperarture')
plt.xlabel('days')
plt.ylabel('temperature')
plt.show
4 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [11]: plt.plot(days,temperature,color='r',marker='o',linestyle="--",linewidth
)
plt.title('ktm temperarture')
plt.xlabel('days')
plt.ylabel('temperature')
plt.show
In [12]: plt.plot(days,temperature,color='y',marker='o',linestyle="--",linewidth
plt.title('ktm temperarture')
plt.xlabel('days')
plt.ylabel('temperature')
plt.show()
5 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [14]: plt.plot(days,temperature,'yo--',linewidth=3,markersize=6)
plt.title('ktm temperarture',fontsize=16)
plt.xlabel('days',fontsize=16)
plt.ylabel('temperature',fontsize=16)
plt.show()
6 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [15]: plt.plot(days,temperature,'yo--',linewidth=3,markersize=6)
plt.title('ktm temperarture',fontsize=16)
plt.xlabel('days',fontsize=16)
plt.ylabel('temperature',fontsize=16)
plt.legend(['tem line'])
plt.show()
In [16]: plt.plot(days,temperature,'yo--',linewidth=3,markersize=6)
plt.title('ktm temperarture',fontsize=16)
plt.xlabel('days',fontsize=16)
plt.ylabel('temperature',fontsize=16)
plt.legend(['tem line'],loc=3)
plt.show()
7 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [17]: plt.plot(days,temperature,'yo--',linewidth=3,markersize=6)
plt.title('ktm temperarture',fontsize=16)
plt.xlabel('days',fontsize=16)
plt.ylabel('temperature',fontsize=16)
plt.legend(['tem line'],loc=5)
plt.show()
In [18]: plt.plot(days,temperature,'yo--',linewidth=3,markersize=6)
plt.title('ktm temperarture',fontsize=16)
plt.xlabel('days',fontsize=16)
plt.ylabel('temperature',fontsize=16)
plt.legend(['tem line'],loc=6)
plt.show()
8 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [19]: plt.plot(days,temperature,'yo--',linewidth=3,markersize=6)
plt.title('ktm temperarture',fontsize=16)
plt.xlabel('days',fontsize=16)
plt.ylabel('temperature',fontsize=16)
plt.legend(['tem line'],loc=7)
plt.show()
9 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
10 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
plt.xlabel('days',fontsize=16)
plt.ylabel('temperature',fontsize=16)
plt.legend(['tem line'],loc=6)
plt.grid(color="k",linestyle="--",linewidth=2)
plt.show()
In [25]: dangadhi_tem=[28.1,29.3,28.1,28.2,27.5,27.2,27.7,27.3,27.4,27,26.5,28.8
len(dangadhi_tem)
Out[25]: 16
In [26]: dangadhi_tem=[28.1,29.3,28.1,28.2,27.5,27.2,27.7,27.3,27.4,27,26.5,28.8
11 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
Ploting Histogram
In [28]: import random
import numpy as np
In [29]: phys_std_age=np.random.randint(18,45,(100))
chem_std_age=np.random.randint(15,40,(100))
In [30]: print(phys_std_age)
print(chem_std_age)
12 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
[41 22 20 26 37 23 28 30 44 42 30 34 40 39 26 18 20 40 37 22 37 39
In [31]: plt.hist(phys_std_age)
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.show()
In [32]: bins=[15,20,25,30,35,40,45]
plt.hist(phys_std_age,bins,rwidth=0.8)
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.show()
13 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [33]: bins=[15,20,25,30,35,40,45]
plt.hist(phys_std_age,bins,rwidth=0.8,histtype='step')
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.show()
In [34]: bins=[15,20,25,30,35,40,45]
plt.hist(phys_std_age,bins,rwidth=0.8,histtype='barstacked')
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.show()
14 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [35]: bins=[15,20,25,30,35,40,45]
plt.hist(phys_std_age,bins,rwidth=0.8,histtype='stepfilled')
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.show()
In [36]: bins=[15,20,25,30,35,40,45]
plt.hist(phys_std_age,bins,rwidth=0.8,histtype='barstacked',align="left"
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.show()
15 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [37]: bins=[15,20,25,30,35,40,45]
plt.hist(phys_std_age,bins,rwidth=0.8,histtype='barstacked',align="right"
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.show()
In [38]: bins=[15,20,25,30,35,40,45]
plt.hist(phys_std_age,bins,rwidth=0.8,histtype='barstacked',align="right"
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.show()
16 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [39]: bins=[15,20,25,30,35,40,45]
plt.hist(phys_std_age,bins,rwidth=0.8,histtype='barstacked',align="right"
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.show()
In [40]: bins=[15,20,25,30,35,40,45]
plt.hist(phys_std_age,bins,rwidth=0.8,color="y",histtype='barstacked'
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.show()
17 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [41]: bins=[15,20,25,30,35,40,45]
plt.hist(phys_std_age,bins,rwidth=0.8,color="y",histtype='barstacked'
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.legend()
plt.show()
In [42]: bins=[15,20,25,30,35,40,45]
plt.hist(phys_std_age,bins,rwidth=0.8,color="y",histtype='barstacked'
plt.hist(chem_std_age,rwidth=0.8,color="m",histtype='barstacked',align
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.legend()
plt.show()
In [43]: bins=[15,20,25,30,35,40,45]
plt.hist(phys_std_age,bins,rwidth=0.8,color="y",histtype='barstacked'
plt.hist(chem_std_age,rwidth=0.8,color="m",histtype='barstacked',align
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.legend()
18 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
plt.show()
In [44]: bins=[15,20,25,30,35,40,45]
plt.hist([phys_std_age,chem_std_age],bins,width=0.8,color=["y","m"],histtyp
#plt.hist(chem_std_age,rwidth=0.8,color="m",histtype='barstacked',align="ri
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.legend()
plt.show()
19 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [45]: plt.hist([phys_std_age,chem_std_age],bins,width=0.8,color=["y","m"],histtyp
#plt.hist(chem_std_age,rwidth=0.8,color="m",histtype='barstacked',align="ri
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.legend()
plt.show()
In [46]: plt.hist([phys_std_age,chem_std_age],bins,width=2,color=["y","m"],histtype
#plt.hist(chem_std_age,rwidth=0.8,color="m",histtype='barstacked',align="ri
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.legend()
plt.show()
20 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [47]: plt.figure(figsize=(15,8))
plt.hist([phys_std_age,chem_std_age],bins,width=2,color=["y","m"],histtype
plt.title('Student ages of physics & chemistry',fontsize=20)
plt.xlabel("Age category",fontsize=16)
plt.ylabel("No of std age",fontsize=16)
plt.legend(['Physics student','Chemeistry student'])
plt.show()
In [49]: style.use('ggplot')
plt.figure(figsize=(15,8))
plt.hist([phys_std_age,chem_std_age],bins,width=2,color=["y","m"],histtype
plt.title('Student ages of physics & chemistry',fontsize=20)
plt.xlabel("Age category",fontsize=16)
plt.ylabel("No of std age",fontsize=16)
plt.legend(['Physics student','Chemeistry student'])
plt.show()
21 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [50]: style.use('ggplot')
plt.figure(figsize=(15,8))
plt.hist([phys_std_age,chem_std_age],bins,width=2,color=["y","m"],histtype
plt.title('Student ages of physics & chemistry',fontsize=20)
plt.xlabel("Age category",fontsize=16)
plt.ylabel("No of std age",fontsize=16)
plt.legend(['Physics student','Chemeistry student'])
plt.grid(axis='both',color='k',linestyle='-.',linewidth=2)
plt.show()
In [52]: classes=['java','python','perl','c+','c++']
class1_std=np.random.randint(10,30,5)
class2_std=np.random.randint(5,40,5)
class3_std=np.random.randint(5,35,5)
22 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [53]: plt.bar(classes,class1_std)
In [54]: plt.barh(classes,class1_std)
23 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [56]: plt.bar(classes,class1_std,width=0.2,align='edge')
In [57]: plt.bar(classes,class1_std,width=0.8,align='edge',color='g',edgecolor
In [58]: plt.bar(classes,class1_std,width=0.8,align='edge',color='g',edgecolor
24 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [59]: plt.bar(classes,class1_std,width=0.8,align='edge',color='g',edgecolor
In [60]: plt.bar(classes,class1_std,width=0.8,align='edge',color='g',edgecolor
plt.legend()
25 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [61]: plt.figure(figsize=(16,9))
plt.bar(classes,class1_std,width=0.5,align='edge',color='g',edgecolor
plt.legend()
In [62]: style.use('ggplot')
plt.figure(figsize=(16,9))
plt.bar(classes,class1_std,width=0.5,align='edge',color='g',edgecolor
plt.legend()
26 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [63]: plt.figure(figsize=(16,9))
plt.bar(classes,class1_std,width=0.5,align='edge',color='g',edgecolor
plt.title("BAR CHART FOR ML CLASS",fontsize=20)
plt.xlabel("Classes",fontsize=20)
plt.ylabel("No of Students",fontsize=20)
plt.legend()
27 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [64]: plt.figure(figsize=(16,9))
plt.bar(classes,class1_std,width=0.5,align='edge',color="b",edgecolor
plt.bar(classes,class2_std,width=0.5,align='edge',color='g',edgecolor
plt.title("BAR CHART FOR ML CLASS",fontsize=20)
plt.xlabel("Classes",fontsize=20)
plt.ylabel("No of Students",fontsize=20)
plt.legend()
28 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [65]: plt.figure(figsize=(20,10))
classes_index=np.arange(len(classes))
width=0.2
plt.bar(classes_index,class1_std,align='edge',color="b",edgecolor='r'
plt.bar(classes_index+width,class2_std,align='edge',color='g',edgecolor
plt.title("BAR CHART FOR ML CLASS",fontsize=20)
plt.xlabel("Classes",fontsize=20)
plt.ylabel("No of Students",fontsize=20)
plt.legend()
29 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [66]: plt.figure(figsize=(20,10))
classes_index=np.arange(len(classes))
width=0.2
plt.bar(classes_index,class1_std,align='edge',color="b",edgecolor='r'
plt.bar(classes_index+width,class2_std,align='edge',color='g',edgecolor
plt.title("BAR CHART FOR ML CLASS",fontsize=20)
plt.xlabel("Classes",fontsize=20)
plt.ylabel("No of Students",fontsize=20)
plt.xticks(classes_index+width,classes)
plt.legend()
30 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [67]: plt.figure(figsize=(20,10))
classes_index=np.arange(len(classes))
width=0.2
plt.bar(classes_index,class1_std,align='edge',color="b",edgecolor='r'
plt.bar(classes_index+width,class2_std,align='edge',color='g',edgecolor
plt.title("BAR CHART FOR ML CLASS",fontsize=20)
plt.xlabel("Classes",fontsize=20)
plt.ylabel("No of Students",fontsize=20)
plt.xticks(classes_index+width,classes,fontsize=16,rotation=30)
plt.legend()
31 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [68]: plt.figure(figsize=(16,9))
classes_index=np.arange(len(classes))
width=.2
plt.bar(classes_index,class1_std,align='edge',color="b",edgecolor='r'
plt.bar(classes_index+width,class2_std,align='edge',color='g',edgecolor
plt.bar(classes_index+width+width,class3_std,align='edge',color='y',edgecol
plt.title("BAR CHART FOR ML CLASS",fontsize=20)
plt.xlabel("Classes",fontsize=20)
plt.ylabel("No of Students",fontsize=20)
plt.xticks(classes_index+width,classes,fontsize=16,rotation=30)
plt.legend()
In [70]: df=pd.read_csv('/home//user2/Documents/ml+python/googleplaystore.csv'
df
Out[70]:
Content
App Category Rating Reviews Size Installs Type Price
Rating
Photo
Editor &
Candy
0 ART_AND_DESIGN 4.1 159 19M 10,000+ Free 0 Everyone
Camera &
Grid &
ScrapBook
Coloring
1 book ART_AND_DESIGN 3.9 967 14M 500,000+ Free 0 Everyone
moana
32 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
Content
App Category Rating Reviews Size Installs Type Price
Rating
U
Launcher
Lite –
2 FREE Live ART_AND_DESIGN 4.7 87510 8.7M 5,000,000+ Free 0 Everyone
Cool
Themes,
Hide ...
Sketch -
3 Draw & ART_AND_DESIGN 4.5 215644 25M 50,000,000+ Free 0 Teen
Paint
Pixel Draw
- Number
4 Art ART_AND_DESIGN 4.3 967 2.8M 100,000+ Free 0 Everyone
Coloring
Book
Varies
My Talking
995 ENTERTAINMENT 4.6 6238 with 100,000+ Paid $4.99 Everyone
Pet
device
Varies
996 Funny Pics ENTERTAINMENT 3.9 9941 with 1,000,000+ Free 0 Teen
device
Funny
997 Quotes ENTERTAINMENT 4.2 23666 3.6M 1,000,000+ Free 0 Teen
Free
In [71]: df.shape
In [72]: df.shape
In [73]: x=df['Rating']
y=df['Reviews']
33 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [74]: plt.scatter(x,y)
34 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [79]: plt.figure(figsize=(16,9))
plt.title('google play store acatter plot')
plt.xlabel('Ratings')
plt.ylabel('Reviews')
plt.scatter(x,y,c='k')
35 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [82]: plt.figure(figsize=(16,9))
plt.title('google play store acatter plot')
plt.xlabel('Ratings')
plt.ylabel('Reviews')
plt.scatter(x,y,c='k',marker="*",s=100)
In [83]: plt.figure(figsize=(16,9))
plt.title('google play store acatter plot')
plt.xlabel('Ratings')
plt.ylabel('Reviews')
plt.scatter(x,y,c='k',marker="*",s=100,alpha=.5)
In [85]: plt.figure(figsize=(16,9))
plt.title('google play store acatter plot')
36 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
plt.xlabel('Ratings')
plt.ylabel('Reviews')
plt.scatter(x,y,c='k',marker="*",s=100,alpha=.5,linewidth=5)
Out[85]: <matplotlib.collections.PathCollection at 0x7f38dbb73358>
In [87]: plt.figure(figsize=(16,9))
plt.title('google play store acatter plot')
plt.xlabel('Ratings')
plt.ylabel('Reviews')
plt.scatter(x,y,c='k',marker="*",s=100,alpha=.5,linewidth=2,edgecolor
37 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [89]: plt.figure(figsize=(16,9))
plt.title('google play store acatter plot')
plt.xlabel('Ratings')
plt.ylabel('Reviews')
plt.scatter(x,y,c='k',marker="*",s=100,alpha=.5,linewidth=2,edgecolor
In [90]: plt.figure(figsize=(16,9))
plt.title('google play store acatter plot')
plt.xlabel('Ratings')
plt.ylabel('Reviews')
plt.scatter(x,y,c='k',marker="*",s=100,alpha=.5,linewidth=2,edgecolor
plt.scatter(x,df['Installs'],c='g',marker="o",s=100,alpha=.5,linewidth
piechart:
38 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
39 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [97]: plt.figure(figsize=(16,9))
plt.pie(y,labels=df['Genres'])
plt.show()
In [110]: df=pd.read_csv('/home//user2/Documents/ml+python/googleplaystore.csv'
x=df['Rating']
y=df['Reviews']
40 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [111]: plt.figure(figsize=(16,9))
plt.pie(y,labels=df['Genres'])
plt.show()
41 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [118]: plt.figure(figsize=(16,9))
explode=[0,0,0,0,0.5,0.4,0,0,0.2,0.3]
plt.pie(y,labels=df['Genres'],explode=explode)
plt.show()
42 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [120]: plt.figure(figsize=(16,9))
explode=[0,0,0,0,0.5,0.4,0,0,0.2,0.3]
colors=['c','r','y','g','k','m','b','r','k']
plt.pie(y,labels=df['Genres'],explode=explode,colors=colors)
plt.show()
43 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [121]: plt.figure(figsize=(16,9))
explode=[0,0,0,0,0.5,0.4,0,0,0.2,0.3]
colors=['c','r','y','g','k','m','b','r','k']
plt.pie(y,labels=df['Genres'],explode=explode,colors=colors,autopct="%0.1f%
plt.show()
44 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [122]: plt.figure(figsize=(16,9))
explode=[0,0,0,0,0.5,0.4,0,0,0.2,0.3]
colors=['c','r','y','g','k','m','b','r','k']
plt.pie(y,labels=df['Genres'],explode=explode,colors=colors,autopct="%0.2f%
plt.show()
45 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [123]: plt.figure(figsize=(16,9))
explode=[0,0,0,0,0.5,0.4,0,0,0.2,0.3]
colors=['c','r','y','g','k','m','b','r','k']
plt.pie(y,labels=df['Genres'],explode=explode,colors=colors,autopct="%0.4f%
plt.show()
46 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [125]: plt.figure(figsize=(16,9))
explode=[0,0,0,0,0.5,0.4,0,0,0.2,0.3]
colors=['c','r','y','g','k','m','b','r','k']
plt.pie(y,labels=df['Genres'],explode=explode,colors=colors,autopct="%0.2f%
plt.show()
47 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [127]: plt.figure(figsize=(16,9))
explode=[0,0,0,0,0.5,0.4,0,0,0.2,0.3]
colors=['c','r','y','g','k','m','b','r','k']
plt.pie(y,labels=df['Genres'],explode=explode,colors=colors,autopct="%0.2f%
plt.show()
48 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [128]: plt.figure(figsize=(16,9))
explode=[0,0,0,0,0.5,0.4,0,0,0.2,0.3]
colors=['c','r','y','g','k','m','b','r','k']
plt.pie(y,labels=df['Genres'],explode=explode,colors=colors,autopct="%0.2f%
plt.show()
49 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [139]: plt.figure(figsize=(16,9))
explode=[0,0,0,0,0.5,0.4,0,0,0.2,0.3]
colors=['c','r','y','g','k','m','b','r','k']
textprops={"fontsize":10,"rotation":20}
plt.pie(y,labels=df['Genres'],explode=explode,colors=colors,autopct="%0.2f%
plt.show()
50 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [141]: plt.figure(figsize=(16,9))
explode=[0,0,0,0,0.5,0.4,0,0,0.2,0.3]
colors=['c','r','y','g','k','m','b','r','k']
textprops={"fontsize":10,"rotation":20,"color":'g'}
wedgeprops={"linewidth":4,"width":1,"edgecolor":"k"}
plt.pie(y,labels=df['Genres'],explode=explode,colors=colors,autopct="%0.2f%
plt.show()
51 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [153]: plt.figure(figsize=(16,9))
explode=[0,0,0,0,0.5,0.4,0,0,0.2,0.3]
colors=['c','r','y','g','k','m','b','r','k']
textprops={"fontsize":10,"rotation":20,"color":'r'}
wedgeprops={"linewidth":4,"width":1,"edgecolor":"k"}
plt.pie(y,labels=df['Genres'],explode=explode,colors=colors,autopct="%0.2f%
startangle=90,textprops=textprops,center=(2,3),shadow=True,wedgepro
plt.show()
52 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [157]: plt.figure(figsize=(20,12))
explode=[0,0,0,0,0.5,0.4,0,0,0.2,0.3]
colors=['c','r','y','g','k','m','b','r','k']
textprops={"fontsize":20,"rotation":20,"color":'r'}
wedgeprops={"linewidth":4,"width":1,"edgecolor":"k"}
plt.pie(y,labels=df['Genres'],explode=explode,colors=colors,autopct="%0.2f%
startangle=90,textprops=textprops,center=(2,3),shadow=True,wedgepro
plt.show()
53 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [162]: plt.figure(figsize=(16,9))
explode=[0,0,0,0,0.5,0.4,0,0,0.2,0.3]
colors=['c','r','y','g','k','m','b','r','k']
textprops={"fontsize":10,"rotation":20,"color":'r'}
wedgeprops={"linewidth":4,"width":1,"edgecolor":"k"}
plt.pie(y,labels=df['Genres'],explode=explode,colors=colors,autopct="%0.2f%
startangle=90,textprops=textprops,center=(2,3),shadow=True,wedgepro
plt.legend()
plt.show()
In [163]: colors=['y','r','g','k','y','r','g','k','y','r','g','k','y','r','g',
len(colors)
Out[163]: 20
In [164]: labels=np.ones(20)
In [173]: plt.figure(figsize=(12,8))
plt.pie([1],colors='k',radius=2.04)
plt.pie(labels,colors=colors,radius=2)
plt.pie([1],colors='w',radius=1.8)
plt.pie([1],colors='y',radius=1.6)
plt.pie(labels,colors=colors,radius=1.5)
plt.pie([1],colors='c',radius=1.4)
plt.pie([1],colors='m',radius=1.2)
54 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
plt.pie(labels,colors=colors,radius=1.1)
plt.pie([1],colors='b',radius=1.0)
plt.pie([1],colors='r',radius=0.8)
plt.pie(labels,colors=colors,radius=0.7)
plt.pie([1],colors='k',radius=0.6)
plt.pie([1],colors='r',radius=0.4)
plt.pie(labels,colors=colors,radius=0.3)
plt.pie([1],colors='y',radius=0.2)
plt.pie([1],colors='k',radius=0.1)
plt.show()
SUBPLOT
55 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [213]: plt.subplot(2,2,1)
plt.pie([1],autopct="%0.1f%%")
plt.subplot(2,2,2)
plt.pie([1,2],autopct="%0.1f%%")
plt.subplot(2,2,3)
plt.pie([1,2,3],autopct="%0.1f%%")
plt.subplot(2,2,4)#,projection='polar'
plt.pie([1,2,3,4],autopct="%0.1f%%")
plt.show()
In [225]: plt.figure(figsize=(20,12))
#plt.subplot(3,2,1) or we can use the following code without commas
plt.subplot(321)
from matplotlib import style
plt.plot(days,temperature,'yo--',linewidth=3,markersize=6)
plt.plot(days,dangadhi_tem,'ro--',linewidth=3,markersize=6)
style.use("ggplot")
plt.title('ktm & Dhangadhi temperarture',fontsize=16,color='g')
plt.xlabel('days',fontsize=16,color='c')
plt.ylabel('temperature',fontsize=16,color='k')
plt.legend(['tem line_for_ktm','Tem line for dhangadhi'],loc=6)
plt.grid(color="k",linestyle="-.",linewidth=2)
plt.subplot(3,2,2)
plt.bar(classes,class1_std,width=0.8,align='edge',color='g',edgecolor
plt.subplot(3,2,3)
bins=[15,20,25,30,35,40,45]
plt.hist(phys_std_age,bins,rwidth=0.8,color="y",histtype='barstacked'
plt.hist(chem_std_age,rwidth=0.8,color="m",histtype='barstacked',align
plt.title('physics student ages')
plt.xlabel("age category")
plt.ylabel("no of std age")
plt.legend()
plt.subplot(3,2,4) #-------------------------------------------------------
#**************************************************************************
56 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
colors=['c','r','y','g','k','m','b','r','k']
textprops={"fontsize":10,"rotation":20,"color":'r'}
wedgeprops={"linewidth":4,"width":1,"edgecolor":"k"}
plt.pie(y,labels=df['Genres'],explode=explode,colors=colors,autopct="%0.2f%
startangle=90,textprops=textprops,center=(2,3),shadow=True,wedgepro
#plt.legend()
plt.subplot(3,2,6)
plt.pie([1],colors='k',radius=2.04)
plt.pie(labels,colors=colors,radius=2)
plt.pie([1],colors='w',radius=1.8)
plt.pie([1],colors='y',radius=1.6)
plt.pie(labels,colors=colors,radius=1.5)
plt.pie([1],colors='c',radius=1.4)
plt.pie([1],colors='m',radius=1.2)
plt.pie(labels,colors=colors,radius=1.1)
plt.pie([1],colors='b',radius=1.0)
plt.pie([1],colors='r',radius=0.8)
plt.pie(labels,colors=colors,radius=0.7)
plt.pie([1],colors='k',radius=0.6)
plt.pie([1],colors='r',radius=0.4)
plt.pie(labels,colors=colors,radius=0.3)
plt.pie([1],colors='y',radius=0.2)
plt.pie([1],colors='k',radius=0.1)
plt.savefig("testfig",format="pdf")
plt.show()
In [216]: plt.figure(figsize=(12,8))
plt.pie([1],colors='k',radius=2.04)
plt.pie(labels,colors=colors,radius=2)
plt.pie([1],colors='w',radius=1.8)
plt.pie([1],colors='y',radius=1.6)
plt.pie(labels,colors=colors,radius=1.5)
plt.pie([1],colors='c',radius=1.4)
plt.pie([1],colors='m',radius=1.2)
plt.pie(labels,colors=colors,radius=1.1)
plt.pie([1],colors='b',radius=1.0)
57 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
plt.pie([1],colors='r',radius=0.8)
plt.pie(labels,colors=colors,radius=0.7)
plt.pie([1],colors='k',radius=0.6)
plt.pie([1],colors='r',radius=0.4)
plt.pie(labels,colors=colors,radius=0.3)
plt.pie([1],colors='y',radius=0.2)
plt.pie([1],colors='k',radius=0.1)
plt.show()
plt.savefig("pie_chart",dpi=100,facecolor="g")#,quality=99()
In [220]: plt.pie([30,50,60],autopct="%0.1f%%")
plt.show()
plt.savefig("pie_chart2",dpi=100,facecolor='y')
Image
In [242]: import matplotlib.image as im
img=im.imread("/home/user2/Documents/ml+python/oleg-ivanov-QhR78CbFPoE-unsp
In [243]: img
Out[243]:
58 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
...,
Out[244]: numpy.ndarray
In [245]: img.ndim
Out[245]: 3
59 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [246]: img.shape
In [249]: plt.axis("off")
plt.imshow(img)
plt.show()
60 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [251]: plt.figure(figsize=(16,12))
plt.axis("off")
plt.imshow(img)
plt.show()
61 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [253]: plt.figure(figsize=(16,12))
plt.axis("off")
plt.imshow(img)
plt.grid(False)
plt.colorbar()
plt.show()
/snap/jupyter/6/lib/python3.7/site-packages/ipykernel_launcher.py:
5: MatplotlibDeprecationWarning: Auto-removal of grids by pcolor()
and pcolormesh() is deprecated since 3.5 and will be removed two mi
nor releases later; please call grid(False) first.
"""
62 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [274]: plt.figure(figsize=(16,12))
plt.axis("off")
plt.imshow(img,cmap="hot")
plt.grid(False)
plt.colorbar()
plt.show()
/snap/jupyter/6/lib/python3.7/site-packages/ipykernel_launcher.py:
5: MatplotlibDeprecationWarning: Auto-removal of grids by pcolor()
and pcolormesh() is deprecated since 3.5 and will be removed two mi
nor releases later; please call grid(False) first.
"""
63 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [255]: plt.figure(figsize=(16,12))
plt.axis("off")
plt.imshow(img,cmap="Accent")
plt.grid(False)
plt.colorbar()
plt.show()
/snap/jupyter/6/lib/python3.7/site-packages/ipykernel_launcher.py:
5: MatplotlibDeprecationWarning: Auto-removal of grids by pcolor()
and pcolormesh() is deprecated since 3.5 and will be removed two mi
nor releases later; please call grid(False) first.
"""
In [268]: chnl=img[:,:,0]
plt.figure(figsize=(16,12))
plt.axis("off")
plt.imshow(chnl,cmap="hot")
plt.grid(False)
plt.colorbar()
64 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
plt.show()
/snap/jupyter/6/lib/python3.7/site-packages/ipykernel_launcher.py:
6: MatplotlibDeprecationWarning: Auto-removal of grids by pcolor()
and pcolormesh() is deprecated since 3.5 and will be removed two mi
nor releases later; please call grid(False) first.
In [269]: chnl=img[:,:,1]
plt.figure(figsize=(16,12))
plt.axis("off")
plt.imshow(chnl,cmap="hot")
plt.grid(False)
plt.colorbar()
plt.show()
65 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
/snap/jupyter/6/lib/python3.7/site-packages/ipykernel_launcher.py:
66 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [270]: chnl=img[:,:,2]
plt.figure(figsize=(16,12))
plt.axis("off")
plt.imshow(chnl,cmap="hot")
plt.grid(False)
plt.colorbar()
plt.show()
/snap/jupyter/6/lib/python3.7/site-packages/ipykernel_launcher.py:
6: MatplotlibDeprecationWarning: Auto-removal of grids by pcolor()
and pcolormesh() is deprecated since 3.5 and will be removed two mi
nor releases later; please call grid(False) first.
In [272]: plt.figure(figsize=(16,12))
plt.axis("off")
plt.imshow(chnl,cmap="nipy_spectral")
plt.grid(False)
plt.colorbar()
67 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
plt.show()
/snap/jupyter/6/lib/python3.7/site-packages/ipykernel_launcher.py:
5: MatplotlibDeprecationWarning: Auto-removal of grids by pcolor()
and pcolormesh() is deprecated since 3.5 and will be removed two mi
nor releases later; please call grid(False) first.
"""
In [288]: cmap="""Accent, Accent_r, Blues, Blues_r, BrBG, BrBG_r, BuGn, BuGn_r, BuPu,
camp_list= cmap.split(sep = ", ")
In [289]: camp_list
Out[289]:
68 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
['Accent',
'Accent_r',
'Blues',
'Blues_r',
'BrBG',
'BrBG_r',
'BuGn',
'BuGn_r',
'BuPu',
'BuPu_r',
'CMRmap',
'CMRmap_r',
'Dark2',
In [285]: save_image_addr_name = []
for i in range(len(camp_list)):
cmap_str = camp_list[i]
save_image_addr_name.append("/home/user2/Documents/ml+python"+"girl_"
print(save_image_addr_name[i])
/home/user2/Documents/ml+pythongirl_'Accent'.png
/home/user2/Documents/ml+pythongirl_'Accent_r'.png
/home/user2/Documents/ml+pythongirl_'Blues'.png
/home/user2/Documents/ml+pythongirl_'Blues_r'.png
/home/user2/Documents/ml+pythongirl_'BrBG'.png
/home/user2/Documents/ml+pythongirl_'BrBG_r'.png
/home/user2/Documents/ml+pythongirl_'BuGn'.png
/home/user2/Documents/ml+pythongirl_'BuGn_r'.png
/home/user2/Documents/ml+pythongirl_'BuPu'.png
/home/user2/Documents/ml+pythongirl_'BuPu_r'.png
/home/user2/Documents/ml+pythongirl_'CMRmap'.png
/home/user2/Documents/ml+pythongirl_'CMRmap_r'.png
/home/user2/Documents/ml+pythongirl_'Dark2'.png
/home/user2/Documents/ml+pythongirl_'Dark2_r'.png
/home/user2/Documents/ml+pythongirl_'GnBu'.png
/home/user2/Documents/ml+pythongirl_'GnBu_r'.png
/home/user2/Documents/ml+pythongirl_'Greens'.png
/home/user2/Documents/ml+pythongirl_'Greens_r'.png
/home/user2/Documents/ml+pythongirl_'Greys'.png
/home/user2/Documents/ml+pythongirl_'Greys_r'.png
In [290]: for i in range(len(camp_list)):
cmap_name = camp_list[i]
plt.figure(figsize=(16,9))
plt.axis("off")
print(cmap_name)
plt.imshow(chnl, cmap=cmap_name)
#plt.colorbar()
#save_image_name1 = "D:\\cmap_image\\"+"girl" + cmap_list[i]
print(save_image_addr_name[i])
plt.savefig(save_image_addr_name[i], orientation='portrate', facecolor
plt.show()
Accent
/home/user2/Documents/ml+pythongirl_'Accent'.png
69 of 70 6/22/22, 10:46 AM
matplotlib http://localhost:8888/notebooks/Documents/ml%2Bpyt...
In [ ]:
70 of 70 6/22/22, 10:46 AM