Other Graphic Plots Types 1. Vertical Bar Plot: Function Format: Bar (X, Y)
Other Graphic Plots Types 1. Vertical Bar Plot: Function Format: Bar (X, Y)
Example
yr=[1988:1994];
sle=[8 12 20 22 18 24 27];
bar(yr,sle,'r')
xlabel('Year')
ylabel('Sales (Millions)')
Example
yr=[1988:1994];
sle=[8 12 20 22 18 24 27];
barh(yr,sle,'k')
xlabel('Sales (Millions)')
ylabel('Year')
3. Stairs Plot
Function format: stairs(x,y)
Example
yr=[1988:1994];
sle=[8 12 20 22 18 24 27];
stairs(yr,sle,'-.k','LineWidth',2)
xlabel('Year')
ylabel('Sales (Millions)')
grid on
title('Stairs Plot Type')
------------------------------------------------------------------
By Eng. Emad Alghamdi
Class of 2020, MATLAB, R2018a
Jeddah College of Technology
MATLAB, Lesson7
4. Stem Plot
Function format: stem(x,y)
Example
yr=[1988:1994];
sle=[8 12 20 22 18 24 27];
stem(yr,sle,'b','linewidth',1.5)
grid on
title('Stem Polt Type')
xlabel('Year')
ylabel('Sales (Millions)')
text(1988.25, 27, 'just an Example for JCT
class')
legend('Years','Sales','Location','NE')
5. Pie Plot
Function format: pie(x,y)
Example
the table below shows the grades that were assigned to a class. The data is used to
create the pie chart that follows.
Grade A B C D E
Number of students 11 18 26 9 5
grd=[11 18 26 9 5];
pie(grd)
title('Class Grades')
Note!
The letters (grades) were added using the Plot Editor.
------------------------------------------------------------------
By Eng. Emad Alghamdi
Class of 2020, MATLAB, R2018a
Jeddah College of Technology
MATLAB, Lesson7
Polar Plots
Polar coordinates, in which the position of a point in a plane is defined by the
angle θ and the radius (distance) to the point, are frequently used in the solution
of science and engineering problems. The polar command is used to plot
functions in polar coordinates. The command has the form:
Where theta and radius are vectors whose elements define the coordinates of the
points to be plotted
Example:
------------------------------------------------------------------
By Eng. Emad Alghamdi
Class of 2020, MATLAB, R2018a
Jeddah College of Technology
MATLAB, Lesson7
theta=[0:5*pi];
r=sqrt(theta);
polar(theta,r)
theta=[0:0.01:5*pi];
r=sqrt(theta);
polar(theta,r,'-k')
title('Fermat''s Spiral')
xlabel('Figure(1)- Polar Plot Type')
ylabel('')
------------------------------------------------------------------
By Eng. Emad Alghamdi
Class of 2020, MATLAB, R2018a
Jeddah College of Technology
MATLAB, Lesson7
y=[22 44 55 66 ];
figure(1)
bar(y)
title('An Example of Bar Plot Type')
xlabel('x axis')
ylabel('y axis')
grid on
figure(2)
bar(y,0.3,'b') % Means 30 percent width
of bars
title('An Example of Bar Plot Type')
xlabel('x axis')
ylabel('y axis')
figure(3)
x=[100:10:130];
bar(x,y,0.5,'m') % 50% and changing the
value of x Axis
title('An Example of Bar Plot Type')
xlabel('x axis')
ylabel('y axis')
grid on
%groupping bars
figure(4)
x1=[2000:1:2004];
y1=[10 30;44 50; 60 70 ;80 60 ; 40 20];
bar(x1,y1,1, 'EdgeColor','k','LineWidth',2)
%100
title('An Example of Bar Plot Type')
xlabel('x axis')
ylabel('y axis')
text(2000, 75, 'Emad''s Class Example')
grid on
legend('Data1','Data2')
Important Note!
There are a lot of options to put on your plot. So, you have to look it up, by using the
Help command or the MATLAB website
------------------------------------------------------------------
By Eng. Emad Alghamdi
Class of 2020, MATLAB, R2018a
Jeddah College of Technology
MATLAB, Lesson7
Plotyy command
Plot specified parameters on X-Y plane with Y-axes on both left and right
sides
Example
clear all,clc,close all
x=linspace(0,4*pi,10);
y=x.^2.*sin(x)
x2=linspace(0,5*pi,20)
y2=x2.^3.*sin(x2);
%case 1
figure(1)
plot(x,y)
hold on
plot(x2,y2)
grid on
title('the y scale for
the blue...
curve is not clear ')
hold off
%case 2
figure(2)
plotyy(x,y,x2,y2)
grid on
title('a great example for Plotyy')
------------------------------------------------------------------
By Eng. Emad Alghamdi
Class of 2020, MATLAB, R2018a
Jeddah College of Technology
MATLAB, Lesson7
------------------------------------------------------------------
By Eng. Emad Alghamdi
Class of 2020, MATLAB, R2018a
Jeddah College of Technology
MATLAB, Lesson7
By clicking on
1. Show plot tools icon, or
2. Edit Plot icon, then double click on the plot,
You’ll have :
For 1
------------------------------------------------------------------
By Eng. Emad Alghamdi
Class of 2020, MATLAB, R2018a
Jeddah College of Technology
MATLAB, Lesson7
For2
Depend on what you doubled clicked on
Or
For more information about using MATLAB Plot Editor, please see the
link : (210) How to Use MATLAB Plot Editor - YouTube
------------------------------------------------------------------
By Eng. Emad Alghamdi
Class of 2020, MATLAB, R2018a
Jeddah College of Technology
MATLAB, Lesson7
Last Example
clear all
clc
t = linspace(-pi,pi, 350);
X = t .* sin( pi * .872*sin(t)./t);
Y = -abs(t) .* cos(pi * sin(t)./t);
plot(X,Y);
fill(X,Y,'r')
title('Thank you Class','FontSize',25)
------------------------------------------------------------------
By Eng. Emad Alghamdi
Class of 2020, MATLAB, R2018a
Jeddah College of Technology
MATLAB, Lesson7
3D plot
clear all
close all
clc
t=0:0.1:6*pi;
x=sqrt(t).*sin(2*t);
y=sqrt(t).*cos(2*t);
z=0.5*t;
plot3(x,y,z,'-r','linewidth',1.5)
grid on
xlabel('\bf xxxxx')
ylabel('\bf yyyyyy')
zlabel('\it zzzz \theta')
title('teheheheh')
------------------------------------------------------------------
By Eng. Emad Alghamdi
Class of 2020, MATLAB, R2018a
Jeddah College of Technology