Graphics in MATLAB | Part 1 - 2D Plotting

Graphics in MATLAB

Now we are here to discuss about the graphical representation in MATLAB before the we need to know about graphics.
Here is a flow chart showing about Graphics.
Graphics is divided into Figure & Animation, figure is further divided into Line, Plot, Text.
Plot and Animation are of two types 2D & 3D as you can see in fig above.

Plot-

Plots are representation of data via chart, so that data can be easily checked throughout, long term data can be easily determined using plots.

In Engineering plot can be used for-
  • Graphical analysis of motion of a car.
  • Analysis of Projection of a ball.
  • Load analysis on a machine, and many other examples.
Plots are of two types.

2D Plots
The basic command for producing simple plot is- plot(x,y)
let us say x & y are array with 8 5 4 3 2 1 & 2 3 4 6 5 4 values respectively then:





This graph will open on an figure window-
Now you can see these graph are made through line, these are line, there are some properties of line.

For a 2D plot, another function plot(x,y,'style') or plot(x,y,'LCM')
where
L is Line Style
C is Color of line
M is Marker


By using these command we will see line, color and marker.


Line Style
Character
Creates
-
Solid Line
--
Dashed
:
Dotted
-.
Dash dot

Color Style
Character
Character
Creates
b
blue
Blue line
g
green
Green line
r
red
Red line
c
cyan
Cyan line
m
magenta
Magenta line
y
k
yellow
black
Yellow line
Black line

Marker Style
Character
Creates
.
Point
P
Circle
x
x-mark
+
Plus
*
Star
s
Square
d
Diamond
v
Triangle down
^
Triangle up
> 
Triangle right
< 
Triangle left
p
Pentagram
h
hexagram


Now let's solve an Example-
% Plotting Value of above given x & y using different marker-



This is using line property here line is dotted and color is blue.

There are few more properties of line and marker.
Line properties-

  • Line Width function is 'line width'
we can use it as plot(x,y,'LCM','line width',2) ; in this case width is 2

Marker Properties-
  • Marker size
  • Marker face color
  • Marker edge color
Here are some more properties of graph
  • Finding min & max point on a graph & Command is given below.
>>axis([xmin,xmax,ymin,ymax])
  • Labeling x axis & y axis & command is given below.
>>xlabel('string')
>>ylabel('string')
  • Title of graph & command is given below.
>>Title('string','font size',3)

  • Text on any point on a graph & Command is given below.
>>text(x,y,'lcm')

  • Command for manually put cursor where to tag text or to get location of any point in given graph.
>>gtext('string')

These are some graph properties, which can be used in MATLAB

Different types of Graph we can draw on matlab
  • Pie Plot
  • Bar Plot
  • Stem Plot
  • Logarithmic Plot
  • Polar Plot 
Pie Plot
Function >>pie(x)
where x is a vector.
Here we can see pie charts for different x & y values.


Bar Plot
Function >>bar(x)
where x has different values in it

Stem Plot
Function >>stem(x,y)


Logarithmic Plot
Function >>loglog(x,y)


Polar Plot
Function >>polar(t,r) or polar (theta,rho)
Polar plot works on providing magnitude and angle.

This is all about 2D Plotting in MATLAB

Comments