0% found this document useful (0 votes)
3 views

Programs of Matplotlib

The document provides examples of various chart types using Matplotlib, including line charts, bar charts, and histograms. It demonstrates how to customize these charts with different styles, colors, and data. Each section includes code snippets that generate the respective charts and display them.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Programs of Matplotlib

The document provides examples of various chart types using Matplotlib, including line charts, bar charts, and histograms. It demonstrates how to customize these charts with different styles, colors, and data. Each section includes code snippets that generate the respective charts and display them.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

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 :

You might also like