0% found this document useful (0 votes)
25 views11 pages

Other Graphic Plots Types 1. Vertical Bar Plot: Function Format: Bar (X, Y)

This document discusses various plot types in MATLAB including bar plots, horizontal bar plots, stairs plots, stem plots, pie charts, polar plots, and 3D plots. It provides examples of how to generate each type of plot using different MATLAB functions like bar(), barh(), stairs(), stem(), pie(), polar(), and plot3(). The examples demonstrate how to customize properties of the plots like colors, line widths, titles, labels, and legends.

Uploaded by

habib khojah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views11 pages

Other Graphic Plots Types 1. Vertical Bar Plot: Function Format: Bar (X, Y)

This document discusses various plot types in MATLAB including bar plots, horizontal bar plots, stairs plots, stem plots, pie charts, polar plots, and 3D plots. It provides examples of how to generate each type of plot using different MATLAB functions like bar(), barh(), stairs(), stem(), pie(), polar(), and plot3(). The examples demonstrate how to customize properties of the plots like colors, line widths, titles, labels, and legends.

Uploaded by

habib khojah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

MATLAB, Lesson7

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)')

2. Horizontal Bar Plot


Function format: barh(x,y)

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

Function format: pie(x,y)

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:

Plotting function r = 3 cos 2 (0 ⋅ 5 θ) + θ for 0 < θ < 2π


t=linspace(0,2*pi,200);
r=3*cos(0.5*t).^2+t;
polar(t,r,'-r')
xlabel('Radius')
ylabel('r=f(\theta)')
title('Polar Plot')

------------------------------------------------------------------
By Eng. Emad Alghamdi
Class of 2020, MATLAB, R2018a
Jeddah College of Technology
MATLAB, Lesson7

Another Example of Polar Plot


Make a polar plot of the function:

The plot, shown in the figure, is Fermat’s spiral.

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

Example : bar plot

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

Using the Plot Editor window to change priorities in the plot


x=[1 1.7 2.5 3.4 5.1 6.5 7.1 8.2 10];
y=[1.8 2.5 6.2 7.2 8 4.5 5.7 6.3 9];
plot(x,y)

Edit Plot Show Plot Tools

Legend the plot

------------------------------------------------------------------
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

You might also like