Professional Documents
Culture Documents
MTE-328(L)
2
Objective
3
Basic of 2D plotting
Graphical representation of dependent and independent
quantity
define X-axis value , and Y-axis value
By Entering in the form of array (same dimension)
A=[1 2 3 4 5 6];
B= [2 4 6 8 10 12];
Plot(A,B)
4
Creating array using step size,
A= [ 1:1:20];
B =2*A;
Plot(A,B)
Length= [1:1:20]
Area=Length.*Length;
plot(Length,Area)
5
Adding Title to the graph
Length= [1:1:20]
Title
Area=Length.*Length;
plot(Length,Area)
title("Length vs area")
6
Adding x-axis labels
Length= [1:1:20]
Area=Length.*Length;
plot(Length,Area)
title("Length vs area")
xlabel("Length")
ylabel("Area")
X-label
Y-label
7
To change x-label size, style and weight
Length= [1:1:20]
Area=Length.*Length;
plot(Length,Area)
'FontWeight','bold')
xlabel("Length",'FontSize',24, 'FontName','Times new Roman',’FontWeight','bold')
ylabel("Area",'FontSize',24, 'FontName',
8
Grid on and off
on
off
9
To equalize the axis
axis square
10
Multiple function on same graph
I=[2:2:40];
P1=I.*I.*2; % at 2 k Ω
P2=I.*I.*3; % at 3 k Ω
plot(I,P1,I,P2)
or
I=[2:2:40];
P1=I.*I.*2; %at 2 k Ω
P2=I.*I.*3; %at 3 k Ω
plot(I,P1)
Hold on
Plot (I,P2)
11
How to differentiate between
these two plot?
12
To change color of each plot
Code Color
I=[2:2:40];
P1=I.*I.*2; %at 2 kΩ w White
P2=I.*I.*3; %at 3 k Ω
P3=I.*I.*4; %at 3 k Ω k Black
P4=I.*I.*5; %at 3 k Ω
P5=I.*I.*6; %at 3 k Ω b Blue
plot(I,P1,'r')
hold on r Red
plot(I,P2,'k')
hold on c Cyan
plot(I,P3,'b')
hold on g Green
plot(I,P4,'c')
hold on m Magenta
plot(I,P5,'g’)
y Yellow
13
To change the style of line
I=[2:2:40];
P1=I.*I.*2; %at 2 kΩ Specifier Line Style
P2=I.*I.*3; %at 3 k Ω
P3=I.*I.*4; %at 3 k Ω - Solid line (default)
P4=I.*I.*5; %at 3 k Ω
P5=I.*I.*6; %at 3 k Ω -- Dashed line
plot(I,P1,'-r') : Dotted line
hold on
plot(I,P2,'--k') -. Dash-dot line
hold on
plot(I,P3,'-.b')
hold on
plot(I,P4,':c')
14
Adding marker
Specifier Marker Type
plot(P4,v4,' -cS) '+'
'o'
Plus, sign
Circle
'*' Asterisk
Line '.' Point
style 'x' Cross
'square' or 's' Square
'diamond' or 'd' Diamond
'^' Upward-pointing triangle
Line marker
'v' Downward-pointing triangle
color
'>' Right-pointing triangle
'<' Left-pointing triangle
'pentagram' or 'p' Five-pointed star (pentagram)
15
Increasing linewidth
plot(x,y1,'r','linewidth',4)
Marker Edge color
plot(x,y1,'rS','linewidth',4,'MarkerEdgeColor','c’)
Marker size
plot(x,y1,'rS', 'MarkerSize',10)
16
Single line command
plot(x,y1,'rS','linewidth',4,'MarkerEdgeColor','c’,
'MarkerSize',10)
17
Adding legend
legend({'@ 2k\Omega','@ 3k\Omega','@ 4k\
Omega','@ 5k\Omega','@ 6k\Omega')},
'FontSize',20,'TextColor','black','LineWidth',3)
18
Two y-axis in single plot
yyaxis left
yyaxis right
19
Multiple plot in single figure
subplot(2,1,1);
x = linspace(0,10);
y1 = sin(x);
plot(x,y1)
subplot(2,1,2);
y2 = sin(5*x);
plot(x,y2)
Row column
Number of figure
subplot(2,1,1);
20
Multiple plot
subplot(2,2,1);
x = linspace(-3.8,3.8);
y_cos = cos(x);
plot(x,y_cos);
title('Subplot 1: Cosine')
subplot(2,2,2);
y_poly = 1 - x.^2./2 + x.^4./24;
plot(x,y_poly,'g');
title('Subplot 2: Polynomial')
subplot(2,2,[3,4]);
plot(x,y_cos,'b',x,y_poly,'g');
title('Subplot 3 and 4: Both')
21
Different type of plots
plot
Area
Histogram
Scatter
stem
pie
bar
barh
comet etc
22
3D plot
t = 0:pi/50:10*pi;
st = sin(t);
ct = cos(t);
plot3(st,ct,t)
23
In Lab Task
Visit google classroom for lab task
24