7) Graphics
7) Graphics
By
Dr. R. R. Manza
Objectives
• Introduction
• 2-D Plotting
• Plot Style Options
• Edit Plot
• Basic Statistics of the Graph
• The Plots Creating
• Animation
• Graphics Object Handling
• 3-D Visualization
• Summary
• You set the properties like line grid, axis limit, style, width etc.
• You can also give title, assign the labels to axis and drown legend in plot.
Plot >>plot(x,y,'style') Plot the 2-D simple graph for both axis
x,y is input parameter
loglog >>loglog(x,y,'style') Plot with logarithmic scales for two axes.
• You can add the title by using the command line and function title on the command
prompt. The title function specifies the value of title properties at the time when
you create plot.
Syntax: - title ('enter your plot title'); %Ex. title ('sign function');
• Add title by using property editor: To start property editor, double click on the axes
in the graph. You can also start property editor by right click on the axes and select
the properties and then select the label and add the title which you want to give and
click on apply.
• Add title by using insert menu: Click the insert menu in the figure window menu
bar and choose title. MATLAB opens a text entry box, enter the title and click any
where in the figure.
5/16/2013 Dept of CS & IT Dr. BAMU Aurangabad 16
Cont..
Legend:
You can create or add the legend in two ways:
• Create legend by using command line: You can create legend to a graph by
using the legend command on command prompt but you must specify the
text labels when you create a legend function. You can also specify its
many aspects like position.
• Create legend by using Insert Menu: You can also create the legend by
using the insert menu, click the insert menu and choose the legend option.
MATLAB automatically create a legend and place it in the upper right
corner of the graph.
5/16/2013 Dept of CS & IT Dr. BAMU Aurangabad 17
Cont..
Legend is created by a separate axes object or box. You can move this
object anywhere in the axes. This object contains one or more lines and text
representing the sample of plot and labels of data set respectively plotted of
the graph. When you edit or resize a legend first start plot in edit mode. The
following figure shows the structure of the legend.
• Add labels using the command prompt: You can add the x, y, and z axis labels by
using commands xlabel, ylabel, and zlabel commands respectively. MATLAB
automatically sets the position of text on the corresponding axis.
5/16/2013 Dept of CS & IT Dr. BAMU Aurangabad 19
Cont..
Text annotation:
You can add the text annotation anywhere in the figure window either using
command prompt or using the plot edit mode in figure window toolbar. You can use
the gtext or text commands for adding text to graph. Text command is used when
you want to position a text annotation according to the point of data set. When you
use gtext command enter your text annotation and press enter or return, move
cursor on graph and push mouse button where you want to place text annotation.
You can also edit the text annotation; firstly start the graph in edit mode and select
the text annotation object to move anywhere in the graph.
You can also draw the arrows anywhere in the figure window. Firstly start the
plot in plot editing mode, then click the arrow or line button in figure window
toolbar or select arrow or line in insert menu. Move cursor at position where
you want to draw arrow or set the cursor position in the figure. Hold the
mouse button down and move the mouse to define the length and direction of
the line or arrow. You can edit the arrow or line using the property editor. You
can change the style, width, color and other characteristics of the arrow or line
annotation using the fields in the panel tab.
1. Bar Graph
MATLAB supports four types of Bar graphs.
a) Vertical Bar Graph:
b) Horizontal Bar Graph
c) 2-D Bar Graph
d) 3-D Bar Graph
To represent user information in any type of bar graph, the following
functions are used:
This function shows the distribution of data values. The histogram hist
function displays data in a Cartesian coordinate system and rose function
displays data in polar coordinate system. The histogram function counts the
number of elements within a range and displays each range as a rectangular
bin. The height of the bins represents the number of values falls within the
range. The hist function shows the distribution of the elements in Y as a
histogram with equally spaced bins between the minimum and maximum
values in Y. A rose plot displays the data after converting it into radians.
Example:
>> hist(h)
5/16/2013 Dept of CS & IT Dr. BAMU Aurangabad 35
Cont..
These graphs describe how to use stem plots and stair step plots to display discrete
data graph, display by function stem, stem3 and stairs. stem displays a discrete
sequence of y-data as stems from x-axis. stem3 function displays a discrete
sequence of z-data as stems from xy-plane. stairs displays a discrete of y-data as
steps from x-axis.
Function Description
contour Displays 2-D isolines generated from values
given by a matrix z.
contour3 Displays 3-D isolilnes generated from values
given by matrix z.
contourf Displays a 2-D contour plots and fills the area
between the isolines with a solid color.
contourc Calculate the contour matrix used by the other
contour functions.
Interactive plotting allows plotting user free hand graph. To select the
points of free hand graph ginput function is used. ginput function allows to
select the mouse or the arrow key to select points to be plotted. This
function returns the coordinate of the selected points.
We can save any sequence of graphs and play the sequence as a movie. This process
has two steps:
2. Use movie to run the movie for specified number of times and rate.
We can create different effect by 3. xor mode erases only the object and
selecting the different erase modes. it is usually used for animation.
Erase modes are useful for dynamic
redrawing. Different erase modes are:
'EraseMode','none','MarkerSize',5); ta',y(3))
hold on end
for i=1:4000
A(1,3) = y(2);
5/16/2013 Dept of CS & IT Dr. BAMU Aurangabad 49
Graphics Object Handling
Graphics object handlings are the basic drawing elements used by MATLAB to display data
and to create graphical user interfaces. The unique identifier of an object is called handle.
This handle can be used to manipulate the object properties or characteristics of an existing
graphics object. Graphics objects contain the number of types such as line, text, patch, axes,
image, surface etc. Axis objects define a region in a figure window and orient their other
information within this region. The different functions create an axis object such as plot,
surf, mesh and bar. There are three basic image types such as indexed, intensity and true
color. Since images are strictly two dimensional hence we can view them only at the default
2-D. The light object defines the different possible sources of the light that affect all patches
and surfaces of the object within the axes. Line object is used to create 2-D and 3D plots. A
single patch contains multiple faces each colored independently with solid or interpolated
colors. Patch object is created by fill, fill3 and contour3 functions. Text objects are nothing
but just the collection of character string. The functions used to handle text objects are title,
xlabel, ylabel, zlabel and gtext.
5/16/2013 Dept of CS & IT Dr. BAMU Aurangabad 50
Common properties of all objects:
Cont..
Property Description
BusyAction Control the way MATLAB handles callback routine interruption defined for the
particular object.
ButtonDownFnc Callback routine that executes when button press occurs.
Children Handles of all this object's children objects.
Clipping Mode that enables or disables clipping
CreateFnc Callback routine that executes when this type of object is created.
DeleteFnc Callback routine that executes when you issue a command that destroys the
object.
HandleVisibility Allows you to control the availability of the object handle from the command
line and from within callback routines.
Interruptible Determine whether a callback routine can be interrupted by a subsequently
invoked callback routine.
Parent The objects parent
Selected Indicates whether object is selected
SelectionHighlight Specifies whether object visually indicates the selection state.
Tag User-specified object label.
Type The type of object ex. figure, line, text, etc.
The set and get function specify and retrieve the value of existing graphics
object properties. These functions are unable to list possible values of fixed
set of properties. Properties of an existing object can change using the set
function and the handle return by the creating function.
Syntax:
Syntax
returned_value=get(object_hanle,'PropertyName');
This chapter covers the basic concept of 2-D and 3-D plotting, overview of