[1] Plot the following data on a line chart and customize the chart according to
the below-given instructions:
Month January February March April May
Sales 510 350 475 580 600
Weekly Sales Report
Write a title for the chart “The Monthly Sales Report“
Write the appropriate titles of both the axes
Write code to Display legends
Display blue color for the line
Use the line style – dashed
Display diamond style markers on data points
import [Link] as pp
mon =['January','February','March','April','May']
sales = [510,350,475,580,600]
[Link](mon, sales, label='Sales', color='b', linestyle='dashed', marker='D')
[Link]("The Monthly Sales Report")
[Link]("Months")
[Link]("Sales")
[Link]()
[Link]()
Ouptut:
[2] Pratyush Garments has recorded the following data into their register for their income from cotton clothes and jeans.
Plot them on the line chart.
Day Monday Tuesday Wednesday Thursday Friday
Cotton 450 560 400 605 580
Jeans 490 600 425 610 625
Apply following customization to the line chart.
Write a title for the chart “The Weekly Garment Orders”.
Write the appropriate titles of both the axes.
Write code to Display legends.
Display your choice of colors for both the lines cotton and jeans.
Use the line style – dotted for cotton and dashdot for jeans.
Display plus markers on cotton and x markers of jeans.
import [Link] as pp
day =['Monday','Tuesday','Wednesday','Thursday','Friday']
ct = [450,560,400,605,580]
js = [490,600,425,610,625]
[Link](day,ct,label='Cotton',color='g',linestyle='dotted',marker='+')
[Link](day,js,label='Food',color='m',linestyle='dashdot',marker='x')
[Link]("The Weekly Garment Orders")
[Link]("Days")
[Link]("Orders")
[Link]()
[Link]()
Output:
[3]. Write a program to plot a range from 1 to 30 with step value 4. Use following algebraic expression to show data.
y = 5*x+2
import [Link] as pp
import numpy as np
x = [Link](1,30,4)
y=5*x+2
[Link](x,y)
[Link]()
[4] Display following bowling figures through bar chart:
Overs Runs
1 6
2 18
3 10
4 5
Import [Link] as pp
overs =[1,2,3,4]
runs=[6,18,10,5]
[Link](overs,runs,color='m')
[Link]('Overs')
[Link]('Runs')
[Link]('Bowling Spell Analysis')
[Link]()
[5] Execute the following codes and find out what happens? (Libraries have been imported
already; plt is the alias name [Link])
(a)
A = [Link](2, 20, 2)
B = [Link](A)
[Link](A, B)
[Link]()
(b)
A = [Link](2, 20, 2)
B= [Link](A)
[Link](A, B)
[Link]()
(c)
X = [Link](1, 18, 2.655)
B = [Link](X)
[Link](X, Y)
[Link]()
[6] Plot a line chart using DataFrame.
import [Link] as plt
import pandas as pd
data = [["Virat",55,66,31],["Rohit",88,66,43],["Samson",99,101,68]]
df = [Link](data, columns = ["Name","Match-1","Match-2", "Match-3"])
[Link](kind='line', color=['red','blue','brown'])
[Link]('Mela Sales Report')
[Link]('Days')
[Link]('Sales in Rs')
[Link]()
[7] Plot a bar chart using DataFrame.
import [Link] as plt
import pandas as pd
data = [["Virat",55,66,31],["Rohit",88,66,43],["Samson",99,101,68]]
df = [Link](data, columns = ["Name","Match-1","Match-2", "Match-3"])
[Link](kind='line', color=['red','blue','brown'])
[Link]('Mela Sales Report')
[Link]('Days')
[Link]('Sales in Rs')
[Link]()
# 7 Simple bar plot
import [Link] as plt
x1=[10, 20, 30, 40, 50]
y1 = [35, 60, 75, 25, 90]
[Link](x1,y1) #width of graph is 0.8 since x1 is numeric data
[Link]()
x2=['a', 'b', 'c', 'd', 'e']
y2 = [35, 60, 75, 25, 90]
[Link](x2,y2) #width of graph is 80% since x2 is string data
[Link]()
Output:
[8] Plot a Histogram chart using DataFrame.
import [Link] as plt
import pandas as pd
dict1={ 'student': ['s1','s2','s3','s4','s5','s6','s7','s8','s9','s10','s11','s12','s13', 's14', 's15'],
'cgpa': [6.1,4.12,8.2,6.4,3.6,9.2,5.5,8.4,6.2,9.8,5.3,3.9,8.1,6.1,2.7],
'numattempts':[1,2,1,3,1,1,2,1,1,2,1,1,3,1,2] }
df1=[Link](dict1)
data = df1['cgpa'] #extract 1D data on which the histogram is to be drawn
[Link]('cgpa range')
[Link]('Number of Students')
[Link]('cgpa range vs Number of students')
[Link]()
[Link](data,bins=10)
[Link]() #bin edges not shown automatically
Output:
#8 Histogram setting bin edges correctly
import [Link] as plt
data= [6.1,4.12,8.2,6.4,3.6,9.2,5.5,8.4,6.2,9.8,5.3,3.9,8.1,6.1,2.7]
#method 1 setting bin edges manually and setting the xticks to bin edges
b1=[3,5.5,7.5,10]
[Link](data, bins=b1)
[Link](b1)
[Link]()
[Link]()
#method2 accessing the bin edges returned by hist function
rtval = [Link](data)
print('rtval=', rtval)
print('rtval[0]=', rtval[0]) #contains frequencies
print('rtval[1]=', rtval[1]) #contains bin edges
[Link](rtval[1]) #set xticks to bin edges
[Link]()
[Link]()
Output:
rtval[0]= [1. 2. 1. 2. 3. 1. 0. 2. 1. 2.]
rtval[1]= [2.7 3.41 4.12 4.83 5.54 6.25 6.96 7.67 8.38 9.09 9.8 ]