-
8/16/2019 Introduction to Python Web Programming and Visualization
1/26
INTRODUCTION TO
PYTHON WEBPROGRAMMING AN
VISUALIZATIONGajendra C. Deshande! Ass".Pr
-
8/16/2019 Introduction to Python Web Programming and Visualization
2/26
We' Ar(h)"e("*re
-
8/16/2019 Introduction to Python Web Programming and Visualization
3/26
He++# W#r+d Pr#,ra-he++#./0123*sr3')n3/"h#n
r)n" 4C#n"en"5"/e6"e7"3h"-+8r8n8r8n4r)n" 9:h"-+;9r)n" 9:head;9r)n" 9:")"+e;He++# W#rd 5 rs" CGIr#,ra-:3h=;9r)n" 9:3'#d/;9r)n" 9:3h"-+;9
-
8/16/2019 Introduction to Python Web Programming and Visualization
4/26
En?)r#n-en" Var)a'+es Pr#,en?./0123*sr3')n3/"h#n
)-#r" #s
r)n" 4C#n"en"5"/e6 "e7"3h"-+8r8n8r8n4@r)n" 4:$#n" s)e;En?)r#n-en":3$#n";:8'r;4@
$#r ara- )n #s.en?)r#n.e/s06 r)n" 4:';F=s:3';6 Fs:8'r;4 F ara-!#s.en?)r#nara-0
-
8/16/2019 Introduction to Python Web Programming and Visualization
5/26
HTML nes an HTML $#r- $#r *ser )n*"
:)n*"; De>nes an )n*" (#n"r#+
:"e7"area; De>nes a -*+")+)ne )n*" (#n"r#+ "e7" area0
:+a'e+; De>nes a +a'e+ $#r an :)n*"; e+e-en"
:>e+dse"; Gr#*s re+a"ed e+e-en"s )n a $#r-
:+e,end; De>nes a (a")#n $#r a :>e+dse"; e+e-en"
:se+e("; De>nes a dr#5d#Jn +)s"
:#",r#*; De>nes a ,r#* #$ re+a"ed #")#ns )n a dr#5d#Jn +)s"
:#")#n; De>nes an #")#n )n a dr#5d#Jn +)s"
:'*""#n; De>nes a (+)(a'+e '*""#n
:da"a+)s"; Se()>es a +)s" #$ re5de>ned #")#ns $#r )n*"(#n"r#+s
:e/,en; De>nes a e/5a)r ,enera"#r >e+d $#r $#r-s0
http://www.w3schools.com/tags/tag_form.asphttp://www.w3schools.com/tags/tag_input.asphttp://www.w3schools.com/tags/tag_textarea.asphttp://www.w3schools.com/tags/tag_label.asphttp://www.w3schools.com/tags/tag_label.asphttp://www.w3schools.com/tags/tag_textarea.asphttp://www.w3schools.com/tags/tag_input.asphttp://www.w3schools.com/tags/tag_form.asp
-
8/16/2019 Introduction to Python Web Programming and Visualization
6/26
Pass)n, In$#r-a")#n *s)n, GMe"h#d123*sr3')n3/"h#n
1 I-#r" -#d*+es $#r CGI hand+)n,)-#r" (,)! (,)"'
1 Crea"e )ns"an(e #$ e+ds>rs"Kna-e $#r-.,e"?a+*e9>rs"Kna-e90
+as"Kna-e $#r-.,e"?a+*e9+as"Kna-e90
r)n" 4C#n"en"5"/e6"e7"3h"-+8r8n8r8n4r)n" 4:h"-+;4r)n" 4:head;4r)n" 4:")"+e;He++# 5 Se(#nd CGI Pr#,ra-:3")"+e;4r)n" 4:3head;4r)n" 4:'#d/;4r)n" 4:h=;He++# Fs Fs:3h=;4 F >rs"Kna-e! +as"Kna-e0r)n" 4:3'#d/;4r)n" 4:3h"-+;4
h""633+#(a+h#s"3(,)5')n3he++#./e/?a+*ee/=?a+*e=
-
8/16/2019 Introduction to Python Web Programming and Visualization
7/26
S)-+e
-
8/16/2019 Introduction to Python Web Programming and Visualization
8/26
Pass)n, In$#r-a")#n *s)n, PMe"h#d
:$#r- a(")#n43(,)5')n3he++#K,e"./4-e"h#d4#s"4;
-
8/16/2019 Introduction to Python Web Programming and Visualization
9/26
Pass)n, Che('#7 Da"a "# PPr#,ra-:$#r- a(")#n43(,)5')n3(he('#7./4 -e"h#d4POST4 "ar,e"4K'+an4;:)n*" "/e4(he('#74 na-e4-a"hs4 ?a+*e4#n4 3; Ma"hs:)n*" "/e4(he('#74 na-e4h/s)(s4 ?a+*e4#n4 3; Ph/s)(s:)n*" "/e4s*'-)"4 ?a+*e4Se+e(" S*'je("4 3;:3$#r-;
123*sr3')n3/"h#n)-#r" (,)! (,)"'
$#r- (,).
-
8/16/2019 Introduction to Python Web Programming and Visualization
10/26
In"r#d*(")#n "# M/SL
Che()n, "he s"a"*s #$ M/SLser?er1 3e"(3)n)".d3-/s+d s"a"*s
S"ar")n, M/SL Ser?er13e"(3)n)".d3-/s+d s"ar"
S"#)n, M/SL Ser?er13e"(3)n)".d3-/s+d s"#
S"ar" M/SL C+)en"1-/s+ Q* *serna-e Q assJ#rd
-
8/16/2019 Introduction to Python Web Programming and Visualization
11/26
C#nne(")n, "# M/SLDa"a'aseimport -/s+.(#nne("#r
from -/s+.(#nne("#r import Err#r def (#nne("06 444 C#nne(" "# M/SL da"a'ase 444 try6 (#nn -/s+.(#nne("#r.(#nne("h#s"9+#(a+h#s"9! da"a'ase9/"h#nK-/s+9! *ser9r##"9! assJ#rd9se(re"90
if (#nn.)sK(#nne("ed06 r)n"9C#nne("ed "# M/SL da"a'ase90
except Err#r as e6 r)n"e0
nally6 (#nn.(+#se0
if KKna-eKK 9KK-a)nKK96 (#nne("0
-
8/16/2019 Introduction to Python Web Programming and Visualization
12/26
C#nne(")n, "# M/SLDa"a'asefrom -/s+.(#nne("#r import M/SLC#nne(")#n! Err#r
from /"h#nK-/s+Kd'(#n>, import readKd'K(#n>,
def *er/KJ)"hK$e"(ha++06 try6 d'(#n>, readKd'K(#n>,0 (#nn M/SLC#nne(")#nd'(#n>,0 (*rs#r (#nn.(*rs#r0 (*rs#r.e7e(*"e4SELECT
-
8/16/2019 Introduction to Python Web Programming and Visualization
13/26
Ma"+#"+)'Matplotlib )s a /"h#n =D +#"")n, +)'rar/ Jh)(h r#d*(es *'+)(a")#n *
)n a ?ar)e"/ #$ hard(#/ $#r-a"s and )n"era(")?e en?)r#n-en"s a(r#ss +a"
Matplotlib )s "he Jh#+e a(a,e@ pylab )s a -#d*+e )n -a"+#"+)' "ha" ,a+#n,s)de -a"+#"+)'@ and matplotlib.pyplot )s a -#d*+e )n -a"+#"+)'.
Pyplot r#?)des "he s"a"e5-a(h)ne )n"er$a(e "# "he *nder+/)n, +#"")n-a"+#"+)'. Th)s -eans "ha" >,*res and a7es are )-+)()"+/ and a*"#-a")"# a(h)e?e "he des)red +#". ,*re and a7es "# a(h)e?e "he des)red +#". Se"")n"hen a*"#-a")(a++/ se" "ha" ")"+e "# "he (*rren" a7es #'je("6
Pylab (#-')nes "he /+#" $*n(")#na+)"/ $#r +#"")n,0 J)"h "he n*-/ $#r -a"he-a")(s and $#r J#r)n, J)"h arra/s0 )n a s)n,+e na-esa(e! na-esa(e #r en?)r#n-en"0 e?en -#re MATLAB5+)e.
-
8/16/2019 Introduction to Python Web Programming and Visualization
14/26
P/+a'6 +#"! sh#J$r#- /+a' )-#r"
>>>from pylab import plot, show>>>y = [ 1.0, 2.4, 1.7, 0.3, 0.6, 1.8 ]>>>plot(y)>>>show()
-
8/16/2019 Introduction to Python Web Programming and Visualization
15/26
P/+a'6 +#"! sh#J>>>from pylab import plot, show
>>> = [ 0.!, 1.0, 2.0, 4.0, 7.0, 10.0 ]>>>y = [ 1.0, 2.4, 1.7, 0.3, 0.6, 1.8 ]>>>plot(y)>>>show()
-
8/16/2019 Introduction to Python Web Programming and Visualization
16/26
P/+a'N*-/>>>from pylab import plot, show
>>>from "#mpy import li"spa$%, si">>> = li"spa$%(0,10,100)>>>y = si"()>>>plot(,y)>>>show()
-
8/16/2019 Introduction to Python Web Programming and Visualization
17/26
P/+a'N*-/>>>from pylab import plot, show
>>>from "#mpy import loa&tt>>>&ata=loa&tt('al#%s.tt',float)>>> = &ata[,0]>>>y = &ata[,1]>>>plot(,y)>>>show()
-
8/16/2019 Introduction to Python Web Programming and Visualization
18/26
P/+a'N*-/from pylab import plot,show
from math import si"from "#mpy import li"spa$%
poi"ts = []ypoi"ts = []for i" li"spa$%(0,10,100) poi"ts.app%"&()
ypoi"ts.app%"&(si"())plot(poi"ts,ypoi"ts)show()
-
8/16/2019 Introduction to Python Web Programming and Visualization
19/26
P/+a'6 7+)-! /+)-! 7+a'e+! 7+)-
Ge" #r se" "he 7 +)-)" #$ "he (*rren" a7es./+)-
Ge" #$ se" "he / +)-)" #$ "he (*rren" a7es.7+a'e+
Se" "he 7 a7)s +a'e+ #$ "he (*rren" a7es.
/+a'e+Se" "he / a7)s +a'e+ #$ "he (*rren" a7es.
-
8/16/2019 Introduction to Python Web Programming and Visualization
20/26
P/+a'from pylab import plot, showfrom "#mpy import li"spa$%, si" = li"spa$%(0,10,100)y = si"()plot(,y)ylim(*1.1,1.1)
lab%l(' ais')ylab%l('y = si" ')show()
-
8/16/2019 Introduction to Python Web Programming and Visualization
21/26
P/+a'6 P+#" S"/+eC#+#r
r6 red,6 ,reen'6 '+*e(6 (/an-6 -a,en"a/6 /e++#J
6 '+a(J6 Jh)"eL)ne s"/+e
4546 s#+)d +)ne45546 dashed +)ne4.46 -ar #)n"s J)"h a #)n"4#46 -ar #)n"s J)"h a ()r(+e
4s46 -ar #)n"s J)"h a s*are
-
8/16/2019 Introduction to Python Web Programming and Visualization
22/26
P+#"from pylab import plot, showfrom "#mpy import li"spa$%, si", $os = li"spa$%(0,10,100)y1 = si"()y2 = $os()plot(,y1,'+*')
plot(,y2,'+**')ylim(*1.1,1.1)lab%l(' ais')ylab%l('y = si" ')show()
-
8/16/2019 Introduction to Python Web Programming and Visualization
23/26
Bar(har" E7a-+e'''
ar $hart &%mo with pairs of bars -ro#p%& for %asy $ompariso".'''import "#mpy as "pimport matplotlib.pyplot as plt
"-ro#ps = !
m%a"sm%" = (20, 3!, 30, 3!, 27)st&m%" = (2, 3, 4, 1, 2)
m%a"swom%" = (2!, 32, 34, 20, 2!)st&wom%" = (3, !, 2, 3, 3)
fi-, a = plt.s#bplots()
i"&% = "p.ara"-%("-ro#ps)barwi&th = 0.3!
-
8/16/2019 Introduction to Python Web Programming and Visualization
24/26
Bar(har" E7a-+eopa$ity = 0.4%rror$o"fi- = /%$olor 0.3
r%$ts1 = plt.bar(i"&%, m%a"sm%", barwi&th, alpha=opa$ity, $olor=b, y%rr=st&m%", %rror+w=%rror$o"fi-, lab%l=%")
r%$ts2 = plt.bar(i"&% barwi&th, m%a"swom%", barwi&th, alpha=opa$ity, $olor=r, y%rr=st&wom%", %rror+w=%rror$o"fi-, lab%l=om%")
plt.lab%l(5ro#p)plt.ylab%l($or%s)plt.titl%($or%s by -ro#p a"& -%"&%r)plt.ti$+s(i"&% barwi&th, (, , , 9, :))plt.l%-%"&()
plt.ti-htlayo#t()plt.show()
-
8/16/2019 Introduction to Python Web Programming and Visualization
25/26
Bar(har" E7a-+e
-
8/16/2019 Introduction to Python Web Programming and Visualization
26/26
W)des(reen Tes" Pa""ern 60
Aspect RatioTest
Sh#*+d aear()r(*+ar0
16x9
4x3