Programs on Matplotlib
CUSTOMIZING LINE CHART: PLOT
# week ,temp ,humidity graph
import matplotlib.pyplot as plt
w=[1,2,3,4,5,6,7,8]
t=[28,34,36,30,32,38,34,32]
h=[30,32,34,28,30,35,33,30]
plt.plot(w,t,'r',linestyle='-.')
plt.plot(w,h,'b',linestyle=':')
plt.show()
OUTPUT :
BAR CHART
Import matplotlib.pyplot as plt
x=[2016,2017,2018,2019,2020]
y=[55,46,30,50,40]
plt.bar(x,y)
plt.show()
OUTPUT :
CUSTOMIZING BAR CHART
# bar chart for year & pass % students
import matplotlib.pyplot as plt
year=[2018,2019,2020,2021]
pas=[28,34,36,30]
# plotting horizontal graph
plt.barh(year,pas,color='b')
plt.show()
OUTPUT :
HISTOGRAM CHART : hist()
import matplotlib.pyplot as plt
data=[2,4,5,6,2,6,8,10,12,12,11,10,4,3,2,5,7,9,11
,12,13,14,15,14,10,9,7,9]
#Plotting Histogram
plt.hist(data)
#Displaying Graph
plt.show()
OUTPUT :
CUSTOMIZING HISTOGRAM CHART
#Histogram for age of students
import matplotlib.pyplot as plt
data=[2,4,5,6,2,6,8,10,12,12,11,10,4,3,2,5,7,9,11
,12,13,14,15,14,10,9,7,9]
#Histogram with 4 ranges and x-ticks
plt.hist(data,bins=[0,4,8,12,16])
plt.xticks([0,4,8,12,16])
plt.show()
OUTPUT :