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

Akhilesh verma - Program9

Program

Uploaded by

Akhilesh verma
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)
5 views

Akhilesh verma - Program9

Program

Uploaded by

Akhilesh verma
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/ 3

Program no.

Matplotlib is a plotting library for the Python programming language and its
numerical mathematics extension of NumPy. In Matplotlib pyplot is a state-
based interface to matplotlib.

matplotlib.pyplot is a collection of functions that make matplotlib work like MATLAB.


Each pyplot function makes some change to a figure: e.g., creates a figure, creates a plotting
area in a figure, plots some lines in a plotting area, decorates the plot with labels, etc.
In matplotlib.pyplot various states are preserved across function calls, so that it keeps track of
things like the current figure and plotting area, and the plotting functions are directed to the
current axes (please note that "axes" here and in most places in the documentation refers to
the axes part of a figure and not the strict mathematical term for more than one axis).
For e.g:

import matplotlib.pyplot as plt


plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()
Program no.9

9. Draw various types of charts using matplotlib


Solution:from matplotlib import pyplot as plt

plt.title('simple graph')

plt.plot([1,2,3],[4,5,1])

plt.show()

plt.bar([0.25,1.25,2.25,3.25,4.25],[50,40,70,80,20],width=.5)

plt.bar([.75,1.75,2.75,3.75,4.75],[80,20,20,50,60],color='r',width=.5)

plt.title('bar graph')

plt.show()

population_age =
[22,55,62,45,21,22,34,42,42,4,2,102,95,85,55,110,120,70,65,55,111,115,80,75,65,54,44,43,42,48]

bins = [0,10,20,30,40,50,60,70,80,90,100]

plt.hist(population_age, bins, histtype='bar', rwidth=0.8)

plt.title('Histogram')

plt.show()

x = [1,1.5,2,2.5,3,3.5,3.6]

y = [7.5,8,8.5,9,9.5,10,10.5]

x1=[8,8.5,9,9.5,10,10.5,11]

y1=[3,3.5,3.7,4,4.5,5,5.2]

plt.scatter(x,y,color='r')

plt.scatter(x1,y1,color='b')

plt.title('Scatter Plot')

plt.legend()

plt.show()

days = [1,2,3,4,5]
Program no.9

sleeping =[7,8,6,11,7]

eating = [2,3,4,3,2]

working =[7,8,7,2,2]

playing = [8,5,7,8,13]

slices = [7,2,2,13]

cols = ['c','m','r','b']

plt.pie(slices,

colors=cols,

startangle=90,

shadow= True,

explode=(0,0.1,0,0),

autopct='%1.1f%%')

plt.title('Pie Plot')

plt.show()

You might also like