0% found this document useful (0 votes)
283 views22 pages

Class 12 IP Ch-2 Data Visualization Using Matplotlib

Matplotlib project

Uploaded by

abhishek985377
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
283 views22 pages

Class 12 IP Ch-2 Data Visualization Using Matplotlib

Matplotlib project

Uploaded by

abhishek985377
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 22
2s eer CB) JHADESWAR, Data Visualization o~ * Data Visualization is a graphical representation of quantitative information and data by using visual elements likegraplis, charts, maps, aoe Nee etc, ow © Ithelps us to understand the significanée of datinby summarizing and presenting a huge amount of data in a simpléjand easy format. * Data Visualization tools provide.actessible’ways to understand outliers, patterns and trends in these data ad Using Pyplot of Matplotlib be In Python, Matplotiit aya yplot is used for Data Visualization. © It was originally by J.D\,HUntér and is built on Numpy arrays for 2D plots ofarrays. NAN \ ‘ ‘ Itisa collection. of futictions that make work like MATLAB. (Created By-SK ABDUL ISRAR PGT (Computer Science) MTech, MCA, BCA Contact-7008443534, 9090042625 JHADESWAR wkernational School Stones How to install matplotlib Type the following command in the command prompt pip install matplotlib ‘ Importing the Library import matplotlib.pyplot import matplotlib.pyplot as plt AX Types of Plotting/Visualizati ion, There are may types of visy lization§,aVailable like: * Line plot \é © Scatter Plot © Histogram * Box plot * Bar Chart «Pie Chart (Created By- SK ABDUL ISRAR, PGT (Computer Science) MTech, McA, BCA, Contact-7008443534, 9090042626 CChapter-S Data Visualization laternattonal School Subject :tnformaties Practices i JHADESWAR SS Basic Parts of a Chart (Created By- SK ABDULISRAR Contaet-7008443534, 9090042625 PGT (Computer Science) MTech, MCA, BCA ‘Subject : Informatics Practices ‘Chapter-5 Data Visualization JHADESWAR taternational School and a y-label. # Axis: They are number line like objectSai graph .lines. ¢ Labels: It used to add names to « Title: It is used to display the'titl « xticks: It sets the current tick locations and labels of the X-axis. © yticks: It sets the current tick locations and labels of the Y-axis. Created By- SK ABDUL ISRAR PGT (Computer Science) MTech, MCA, BCA 6 Contact-7o08443534, 9090082 Subject: nformaties Practices Cs}; JHADESWAR CChapter-5 Data Visualization witernational School Line Chart/Plot “ Aline chart or line graph can be created using the plot() function available in pyplot module. Rn Syntax: 7 . Matplotlib.pyplot.plot(x-axis, y-axis, color, linewidth or Iw, linestyle or Is, marker, markersize, markeredgecolor)s d=[3,7,4,8] plt.plot(d) pitshow() {8 Note: In the above example list ‘d’ is considered as y-axis of plot. (created By-SK ABDUL ISRAR PGT (Computer Science) MTech, MCA, BCA Contact-7008443534, 9090042626 rs (By HARESMAR Chapter-5 Data Visualization QED trternationat Schoot ‘style Style Abbreviation Solid Dashed Dashdot Dotted “Color Character [Color Name bh WV Blue ‘Vic Cyan Green Black Magenta Red White Yellow Created By- SK ABDUL ISRAR PGT (Computer Science) MTech, MCA, BCA ‘Contact-7008443534, 9090042626 Subject: Informatics Practices CChapter-5 Data Visualization Ex:-2 JHADESWAR iternational sehool import matplotlib.pyplot as plt. plt.plot([3,7,4,8],[10,15,20,25], color='g', linestyle: pit.title(‘Line Graph’) plt.ylabel('Y-axis') plt.xlabel('x-axis') plt.grid(True) plt.show() ‘Created By-SK ABDUL ISRAR PGT (Computer Science) MTech, MCA, BCA Subject: Informatics Practices Chapter-5 Data Visualizati ‘Contaet-7008443534, 9090042625 JHADESWAR aternattonal Sence! Symbol, triangle’ down) riangle up triangleyIeft tiatigle right tri. down tri_up tri_left tri_right ‘octagon. square pentagon plus (filled) star Thr % fo |e [+ [e [em (oly Js ]>|< |v Ja > |< le hexagon oH # Created By- SK ABDUL ISRAR GT (Computer Science) MTech, MCA, BCA hexagon? 4 Contact-7on844a534, 90900826 ‘Subject : Informatics Practices. Chop bat uation AES WAR, a x’ x "x" x (filled), "Dp" diamond J thingdiamond?™ vine \< inline: OCTICKLEFT) lickleft 1 (TICKRIGHT) 2 (TICKUP)_ 3 (TICKDOWN) Fr 4(CARETLEFT) _& “f 5 (CARETRIGHD) A. caretright 6(CARETUP) 2%, fia’ caretup 7(CARETDOWN). caretdown 8 (CARETLEFTBASE)..” caretleft (centered at base) 9 (CARETRIGHTBASE) caretright (centered at base) 10 (CARETUPBASE) caretup (centered at base) 11 (CARETDOWNBASE) caretdown (centered at base) plus ‘Created By- SK ABDULISRAR PGT {Computer Science) MTech, MCA, BCA Subject: informatics Practices JHADESWAR ‘Chapter-5 Data Visualization Wikernational School Ex:-3 (With Markers) import matplotlib.pyplot as plt pit.plot({3,7,4,8],[10,15,20,25], marker="*", markersiz plt.title('Line Graph’) plt.ylabel('Y-axis') plt.xlabel('x-axis') plt.grid(True) pit.show() a (Created By- SK ABDULISRAR PGT (Computer Science) MTech, MCA, BCA Contact-7008443534, 9090042626, Subject : Informatics Practices, JHADESWAR Chapter-5 Data Visualization international School Ex:-4 (With xticks & yticks) import matplotlib.pyplot as plt date=[25,26,28] temp=[8.5,10.5,6.8] plt.plot{date,temp) plt.xlabel('Date’) Datewise Temperature plt,ylabel(‘Temperature’) 3 Hh a plt.title(‘Datewise Temperature’) plt.grid(True) plt.yticks(temp) plt.xticks(date) plt.show() | | | | ! 7 q q 3s 3 = ate 3 Created By: SK ABDUL ISRAR PGT (Computer Science) MTech, MCA, BCA (Conttact Tones ss=2%, S0mucaress, ‘Subject: Informatics Practices : ee CB} JHADESWAR Saving plot to files We can the figure in two ways:- a) by clicking the Save button on the GUI panel. b)by using savefig() method Ex: import matplotlib.pyplot as plt pit.plot([3,7,4,8],[10,15,20,25], markers" plt.title('Line Graph’) aie : sai plt.ylabel(’Y-axis') é plt.xlabel('x-axis") pit.grid(True) p ; plt.savefig("Student.png’) %»_ plt.show() » * euch Created By- SK ABDULISRAR PGT (Computer Science) MTech, MCA, BCA, 6 Contact-7008443534, 90900425 subject informatie Pracles & JHADESWAR ‘Chapter-5 Data Visualization Wakernatlonal school Line Chart by using a Pandas Series We can create Line chart from Pandas Series by using plot(o pandas library. Ex: import matplotlib.pyplot as pit import pandas as pd pltd=pd.Series([10,12,15,30],['a','b’,'c')'d'])" pltd.plot(kind='line') plt.title(‘Sectionwise Student : pit.xlabel('Sections') \, ¥ Sects Studer stat plt.ylabel('Strength') pit.show() ‘Created By- SK ABDUL ISRAR = i PGT (Computer Science) MTech, MCA, BCA Contact-7008443534, 9090042626 ‘Subject : Informatics Practices JHADESWAR CChapter-5 Data Visualization D international School Line Chart by using a Pandas DataFrame We can create Line chart from Pandas DataFrame by using’ let(Jof pandas library. Ex: import matplotlib.pyplot as pit import pandas as pd weight=[20.5,21.5,24,6,25.8,27.4,30.2, df=pd.DataFrame({'Height': height, Weigh weight}) plt.plot(df Weight,df-Height) .» plt.xlabel('Weight in KG’) plt.ylabel('Height in CM’) “ plt.title(‘Average Height ventas Weight') 5». plt.show() os, fo Created By- SK ABDUL ISRAR PGT (Computer Science) MTech, MCA, BCA CContact-7008443534, 9090042626 ‘Subject sInformaties Practices CChapter-s Data Visualization Line Chart by using a CSV File Ex: a 36. a “a 5 40 39, 3s) 40 Created By- SK ABDUL ISRAR PGT (Computer Science) MTech, MCA, BCA Subject : informatics Practices Chapter-5 Data Visualization import pandas as pd import matplotlib.pyplot as pit df=pd.read_csv('weather.csv') df.plot(kind='line’,color=['red','green', "blue! plit.title('Weather Report’) plt.xlabel('Days') plit.ylabel(‘Temperature in degree ¢ re ticks=df.index.tolist() plt.xticks(ticks,df.Day) plit.show() ‘Created By-SK ABDUL ISRAR PGT (Computer Science) MTech, MCA, BCA 33 Friday _ 39 Saturday Contact-7008443534, 9090042625 ‘Sey Weilay Teli Wea Tadayfily ST on JHADESWAR Uxternational School JHADESWAR D wrternational Seker) Contact-7onga43sas, sont 4 ‘Subject : Informatics Practices JHADESWAR Chapter-S Data Visualization lakernational School Line Plot with multiple lines Ex: import matplotlib.pyplot as pit x=([1,2,3] y=15,7,4] plt.plot(x,y,label='First Line') x2=[1,2,3] y2=[10,11,14] : ew Geaph plt.plot(x2,y2,label='Second:Line!) plt.xlabel('Plot Number’)... : plt.ylabel('Important Variables!)/) plt.title('New Graph" ') pit.legend() plt.show() nN ibe ib ile is abe ais abe 2m ame ql ‘Created By- SK ABDUL ISRAR PGT (Computer Science) MTech, MICA, BCA Contact-7008443534, 9090042626 ‘Subject : Informatics Practices JHADESWAR Chapter-5 Data Visualization D international School Q) Write the code for the following graph which will display the different style multiline it in same plot jae > bQeiB Created By- SK ABDUL ISRAR PGT (Computer Science) MTech, MCA, BCA 4] Contact-7008443534, 9090042626 Subject: Informatics Practices CChapter-5 Data Visualization import matplotlib.pyplot as pit .0,20,30) x2=[10,20,30] y2=[40,10,30] plt.plot(x1,y1,label="l plt.plot(x2,y2,labe plt.xtabel('x-axis') plt.ylabell'y-axis') plt.title('Plot with differ pit.legend() plt.grid() plt.show() ‘Created By- SK ABDULISRAR PGT (Computer Science) MTech, MCA, BCA ‘Subject: nformaties Practices Chapter-5 Data Visualization Multiple plots in a same Ex: import matplotlib.pyplot as plt x=[1,2,3] y=[5,7,4] pit.subplot(2,1,1) plt.plot(xy) plt.xlabel(‘Item') plt.ylabel('Value') plt.grid(True) plt.title('First Chart’) plt.subplot(2,1,2) pit.plot(x2,y2) pit.xlabel('item'). pitylabell Value) = pit.grid(True) pit.title('Second Chart!) plt.show() Created By- SK ABDULISRAR PGT (Computer Science) MTech, MCA, BCA indow using subplot! Contact-7008443534, 9090042626 &. Ne re AX First Chart yoo 335, 480195200. 225 ako i 2 0 275 300 Contact-7o0ga4asa4, 909004262 subject: Informatles Practices CChapter-5 Data Visualization JHADESWAR | Multiple plots in a same window adjusting subplots Ex: import matplotlib.pyplot as pit x-[1,2,3] y=15,7,4) a plt.subplot(2,1,1) © ist chart plt.plot(x,y) Tf plt.xlabell'item') plt.ylabel('Value’) plt.grid(True) T plt.title('First Chart’) ee ee plt.subplots_adjust(hspace=0.5, wspats0,5), ve aoe tis 2h0 2s 12,3) Second Chart y2=[10,11,14] = plt.subplot(2,1,2) pit.plot(x2,y2) pit.xlabel('Item') pit.ylabel('Value’) - pitgrid(True) 350 1/5 200 235 250 plt.title(‘Second Chart’) a pit-show() : ‘Created By- SK ABDUL ISRAR PGT {Computer Science) MTech, MCA, BCA CContact-7008443534, 9090042626 ‘Subject : Informatics Practices JHADESWAR CChapter-5 Data Visualization laternational School Bar Chart/Plot ‘A Bar graph or chartis a graphical display of data using bars‘f different heights. ‘« Pyplot offers two bar functions: : a) bar() : To create vertical bar graph b) barh() : To create horizontal bar graph ‘Syntax: plt.bar(xsequence, ysequence, width=, cal Note: ~~ Ex: (Vertical Bar) @ import matplotlib.pyplot as Ib i i',Mumbai’ Bangalore’, Chennai'] 1000000, 3000900;2500000, 1500000) Ju plt.bar(cities,population) “> plt.xlabel(‘Cities') . plt.ylabel('Population’) plt.show() Sc etieeneeeeeen: ‘Created By- SK ABDUL ISRAR PGT (Computer Science) MTech, MCA, BCA Contact-7008443534, 9090042626 ‘Subject : Informatics Practices R Chapter-5 Data Visualization tkernational Sehoot Ex: (Horizontal Bar) import matplotlib.pyplot as plt cities=[‘Delhi’,'Mumbai','Bangalore’,'Chennai'] population=[2000000,3000000,2500000,1500000] * plt.barh(cities, population) pltylabel('Cities') plt.xlabel('Population’) plt.show() Created By- SK ABDULISRAR PGT (Computer Science) MTech, MCA, BCA ‘Subject : Informatics Practices Chapter-5 Data Visualization Ex: (With width & color) import matplotlib.pyplot as plt cities=['Delhi’, Mumbai','Bangalore', 'Chennai'] ey, poputation=[2000000,3000000,2500000,1500000] \, SS plt.bar(cities, population, width=0,3,color: plt.xlabel('Cities') pltylabel('Population’) plt.show() JHADESWA! International Schoc eum Created By- SK ABDULISRAR ies PGT (Computer Science) MTech, MCA, BCA — a | 6 Contact-7008443534, 909004262 Peas Sublet: norma bracts ‘Chapter Data Visualization Se BS, AHADESWAR, Ex: (With different widths & colors) import matplotlib.pyplot as plt citi 'Delhi’,’Mumbai’,'Bangalore','Chennai') populatior 2000000,3000000,2500000,1500000) plt.bar(cities, population, width=[0.5,0.2,0.4,0,6f) colo plt.xlabel('Cities') : plt,ylabel('Population’) plt.show() (Created By- SK ABDULISRAR PGT (Computer Science) MTech, MCA, BCA Subject : Informatics Practices JHADESWAR Chapter-S Data Visualization tutermational School Q) Write the python code for the below graph. Favourite Type of Movies import matplotlib.pyplot as pitinimpy ‘as ni movies=['Comedy’,‘Action’,Romance''Drama','SciFi'] 15,6,1,4) Re AD p.arange(len(movies)), 3%, pit.bar(pos,types,align='center' ,color='orange') plt.xticks(pos, movies)", pit ylabel('People') ‘al plt.title('Favourite Type of Movies') ql pitshow() g Created By- SK ABDULISRAR contact-7008443534, 9090042626 PGT (Computer Science) MTech, MCA, BCA Subject: Informatie Practices CChapter-5 Data Visuallzation Q) Write the python code for the below graph. Programming Language Usage import matplotlib.pyplot as pltsnimpy sn langs=['Python', 'C+¥', Java’, 'Pelt!, ‘Scala’, 'Lisp'] performance=[10, 8, 6, 4):2;, as} Pos=np.arange(len(langs)) \ pit.barh(pos, performance, pltyticks(pos, fangs)", plt.xlabel('Usage’)™= plt.title('Programming Language Usage’) pit.show() (Created By- SK ABDULISRAR PGT (Computer Science) MTech, MCA, BCA ‘Subject : Informatics Practices Chapter-5 Data Visualization Multicolumn bar chart ‘center’, color="red") Q) Write the python code to create a plot as given. below: JHADESWAR aternational Sohoot pae27. Contact-7008443534, 9090042625 cen Happines index across cites by gender » ©. 5 He 70 20 0 ooh Beling Washington Toyo go Rho tscow AEPFQE Created By- SK ABDULISRAR PGT (Computer Science) MTech, MCA, BCA, ‘Subject: Informatics Practices Chapter-5 Data Visualization G8; JHADESWAI import matplotlib.pyplot as plt,numpy as np \gton’,Tokyo','Moscow'] «” Aternattonal SehooL city=['Delhi’,'Beijing’,'Washin male=[60,40,70,65,85) female=[30,60,70,55,75] pos=np.arange(len(city)) pit.bar(pos,male,label="male',widt! plt.bar(pos+0.2,female,label="femal plt.xticks(pos,city) plt.xlabel(‘city') : plt.ylabel(‘Happines Index’) plt.title(‘Happines Indéea plt.legend() , pit.savefig(‘Happy.png’) pit.show() Fer natinnodenanan Contact-7008443534, 9090042626 PGT (Computer Science) MTech, MCA, BCA ‘Subject: Informatics Practices JHADESWAR CChapter-5 Data Visualization iAkernational School Q) Write the python code to create a plot as given below: ted By- SK ABDULISRAR (Computer Sclence) MTech, MCA, BCA Coripes Jonenasest, agnontae2s Chapters Data Visualization import matplotlib.pyplot as plt,numpy as np "Team A’,'Team B’,'Team C','Team D’,'Team E'] r1=[35,55,10,90,70] '12,55,78,45,90] r3=[15,25,45,25,89] x=np.arange(len(teams)) plt.bar(x,r1,width=0,2,label='Round 1') plt.bar(x+0.2,r2,width=0.2,label='Round 2') plt.bar(x+0.4,r3,width=0.2,label="Round 3') plt.xticks(x,teams) ~~ plt.xlabel("Teams') plt.ylabel('Scores') plt.legend() . plt.savefig('Scores.piig') plt.show() » © % ‘Created By- SK ABDUL ISRAR a : PGT (Computer Science) MTech, MCA, BCA ‘Subject : Informatics Practices Chapter-5 Data Visualization Bar Chart by using a Series E JHADESWAR International School import matplotlib.pyplot as plt import pandas as pd <> pitd=pd.Series({30,42,35,20],['A','B ts pltd.plot(kind='bar') plt.title('Sectionwise Student Strengtiy ) pit.xlabel('Sections') plt.ylabell'Strength’) ‘ Sectonwise Student strength plt.show() Ors «. 22 Created By- SK ABDUL ISRAR eae a j GT (Computer Science) MTech, MCA, BCA Contact-7o08443534, 9090042626 ject : Informatics Practices Chapter-5 Data Visualization gar Chart by using a DataFrame GE) MIAPESWAR, EX: import matplotlib.pyplot as pit import pandas as pd std={'2019':[10,12,15,30], 2020':[16,25,22,30}, 2021':[19,22,29,32}}) Seton Sten Stn pltd=pd.DataFrame(std,index=[! pltd.plot{kind="bar') plt.title('Sectionwise Studei plt.xlabel('Sections') ° plt.ylabel('Strength’) ®: pit.show() ee: crested By-SK ABDUL ISRAR Pat|Computer Science) MTech, MCA, BCA CContact-7008443534, 9090042625 JHADESWAR _ Subject : Informatics Practices taternattonal School Chapter-5 Data Visualization Ex: (With align and stacked attribute) import matplotlib.pyplot as plt import pandas as pd Secret eg | std=('2019':[10,12,15,30], __ '2020':[16,25,22,30], '2021':[19,22,29,32]} pltd=pd,DataFrame(std,index: _Pit.xlabel('Sections') _Pit.ylabel('strength') Pltshow() Contact-7008443534, 9090042626 By mae Subject: informatics Practices ASARESW, ‘Se AR Chapters Data Visualization Bar Chart by using a CSV File Ex: k1_|Woek2 |Wook3 [Day 36] 37|___36| Sunday 3s, 39 40/Monday__ aaa Baan a Weesday 39,404 \Thursday| ( St gat alee 40,38, —_39/Saturday ] (Created By- SK ABDUL ISRAR PGT (Computer Science) MTech, MCA, BCA Contact-7008443534, 9090042625 Sperone vance {35}, JHADESWAR import pandas as pd import matplotlib.pyplot as plt df=pd.read_csv('Weather.csv') df.plot(kind='bar',color='red','green','blue! ) plt.title('Weather Report') plt.xlabel('Days') pit.ylabel('Temperature in degree c’ ticks=df.index.tolist() plt.xticks(ticks,df.Day) uJ ae pit.show() : i wa Lary Haectc| | Created By- SK ABDULISRAR PGT (Computer Sclence) MTech, MCA, BCA, Subject : informatics Practices Chapter-5 Data Visualization JHADESWAR International School Histogram Chart a specifiéd tange’of values (called bins), * Itis similar to a vertical bar chart, However/ia histogtant, unlike a vertical b; chart shows no gaps between the bars, keen * Pyplot offers hist() function to create histog sin chart. ‘Syntax: pyplot.hist(x, bins, weights ‘type,color,orientation) VY X bins attribute: Controls h weights attributa Iti histogram. Which allows us overall histogram. ed to assign weights to each data point in our Control the contribution of each data point to the ‘created By- SK ABDUL ISRAR et {Computer Science) MTech, MCA, BCA Contact-7008443534, 9050042626 peered & JHADESWAR Q) The heights of 10 students of eight grade are given below: Height_cms=[145,141,142,142,143,144,141,140,143;144] Write suitable python code to generate a histogram basedion the given data, along with an appropriate title and both axis title labels. Also\give'suitable python statement to save this chart. & s Ans: import matplotlib.pyplot as plt Height. emsr[145, 101,242,242, 143,144,44140,143,144 plt.hist(Height_cms) ‘ ht chat tant plt.title('Height Chart of Students’): . 00: plt.xlabel('Height in cms') plt,ylabel('Number of students’) * __ Plt.savefig(‘height.pné’) 2 § soo _ Pitshow() \ : Ccontact-7008443534, 9090042626 ala}: Feriel8+SK ABDUL ISRAR JHADESWa, ternational Sey, ‘Subject : Informatics Practices Chapter-5 Data Visualization Ex: (With bins attribute) import matplotlib.pyplot as plt ‘ std_wt=[19,25,30,35,25,60] a é plt.hist(std_wt,bins=[0,10,20,30,40,50,60])° °'.-' plt.show() Created By- SK ABDULISRAR PGT (Computer Science) MTech, MCA, BCA Contact-7008443534, 9090082625 ‘Subject : Informatics Practices ‘Chapter-5 Data Visualization JHADESWAR, Ex: (With weights attribute) import matplotlib.pyplot as plt std_wt=[19,25,30,35,25,60] pit hist(std_wt,bins=[0,10,20,30,40,50,60), weights: \10,35,40,6.8) plt.show() ¢ % Created By- SK ABDUL ISRAR PGT (Computer Science) MTech, MCA, BCA ‘Chapter-5 Data Visualization D international Senool Ex: (With Color and histtype attribute) import matplotlib.pyplot as plt scores = [55, 62, 77, 85, 90, 93, 58, 79, 88, 95, 60} wts = [1, 1, 3,2, 1,1, 1,3, 2,2, 1) bns = [50, 60, 70, 80, 90, 100) t . plt-hist(scores, bins=bns, weights=wts, color='r'phisttype='step') plt.xlabel('Scores') y" plt.ylabel('Weighted Frequency’) plt.title(‘Weighted Histogram with:Cust plt.show() ~t tara wth custom Subject: Informatie Practices 3 JHADESWAR & ‘arated By- SK ABDUL ISRAR P5T {Computer Science) MTech, MCA, BCA Contact-7008443534, 9030042626 Subject informatics Practices Saher CS) HAPESWAR, Q) Write the code to plot the given graph import matplotlib.pyplot as plt X=[7,19,25,33,55] i Plt hist(x,bins=[0,10,20,30,40,50,60],weights=[20,17,45,35,8]) It.show() Fan canpart.Taeneaniee anenesese Subject: informatie races JHADESWAR CChapter-S Data Visualization D wikernational school Ex: (With histtype and orientation attribute) i import matplotlib.pyplot as plt 4 b=[10,20,11,21,9] 4 g=[11,23,10,9,6] Be, pit-hist([b,g], bins=[0,10,20,30),rwidth=0.9,color=[' 'g'|,label=['Boys','Girls'], histtype="barstacked' orientation="horizontal') ‘ plt.xlabel('Range') . plt.ylabel('Ratio') plt.legend() plt.show() (Created By- SK ABDULISRAR PGT (Computer Science) MTech, MCA, BCA Subject : informatics Practices CChapter-5 Data Visualization Ex: import matplotlib.pyplot as pit b=[10,20,11,21,9] g=[11,23,10,9,6] plt.hist(b,bins=[0,10,20,30}, histtype='step') plt-hist(g,bins=[0,10,20,30]) : pit.show() JHADESWAR International Sencol Created By- SK ABDULISRAR PGT (Computer Science) MTech, MCA, BCA, Contact-7008443534, 9090042626

You might also like