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

T.Y Python Practical 12

Python Practical Notes

Uploaded by

rutujapawar.1408
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

T.Y Python Practical 12

Python Practical Notes

Uploaded by

rutujapawar.1408
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

PYTHON PRACTICAL 12

Graph plotting

Q1) Explain plt.plot function with suitable examples.


Ans: To plot simple 2D graphs, we use plot function from matplotlib. plot function inly plots the
provided data which is displayed by the calling the show() function. If there are two vectors x and y,
plt.plot(x , y) or plot (x , y) plots x versus y. Consider the example :

Output:

Q2) Explain different types of colours and pattern available in matplotlib with examples.
Ans : With matplotlib, we can set the colour of lines, line width, line style and marker.
 To set a particular colour we mention it in plot function only .for e.g. plot (x ,y , ‘r’)
Colour Description
y Yellow
m Magenta
c Cyan
r Red
g Green
b Blue
w White
k Black
 For linewidth we use the linewidth or lw keyword argument.
for e.g. plot (x , y , ‘r’,lw = 0.5)
plot (x , y , ‘r’,lw = 2)

 The linestyle is selected using linestyle or ls keyword argument.


for e.g. plot (x ,y , ‘r’, ls = ‘--’)

Line Style Description


- Solid line
-- Dashed line
: Dotted line
-. Dash-dot line

 The line marker can be selected using the marker keyword arguments.
for e.g. plot(x ,f , label= “$\sin x$” , marker= ‘o’)
plot(x ,f , label= “$\sin x$” , marker= ‘+’)

Marker Description
O Circle
+ Plus sign
* Asterisk
. Point
X Cross
- Horizontal line
__ Vertical line
s Square
d Diamond
p Pentagram
h Hexagramm

Q3) Plot the graph of f(x)= sinx in [-2π, 2π] with red dashed line with circle markers.

Output:
𝟏
Q4) Plot the graph of f(x) = xsin𝐱𝟐 in [-5,5].

Output:
Q5) Plots the graphs of sinx, cosx, ex and x2 in [0,5] in one figure with (2 X 2) subplots.

Output:
Q6) Generate 3D wireframe Plots for the following function.
f (x,y)= ex2+y2 for x 𝝐 [0,2π], x 𝝐 [0,2π]

Output:
Q7) Explain legend( ) command with suitable example.
Ans : A legend is a key to a graph that identifies the different groups of data in a chart by colour,
pattern, or a symbol. We decorate a figure or graph by titles, axis labels, and legends. To set the title
we use title attribute after plotting, similarly for axis labels we use xlabel, ylabel and for legends, we
use legend() . Before applying legend(), we need to label the graph first.
The legend function takes an optional argument loc that can be used to specify the location of the
legend.
Python Code Location of legend
Legend(loc=1) Upper right corner
Legend(loc=2) Upper left corner
Legend(loc=3) Lower left corner
Legend(loc=4) Lower right corner
Legend(loc=0) Matplotlib decides the optimal location

Example:

Output:
Q8) Plot a Cardiod r = a+ acos (θ) where, a = length of axis of cardiod. Take a = 5.

Output:

You might also like