Geoscience Reference
In-Depth Information
subplot(2,1,1), plot(x,y1,'r--')
subplot(2,1,2), bar(x,y2)
For example the Figure Window is divided into two rows and one column.
h e 2D linear plot is displayed in the upper half of the Figure Window and
the bar plot appears in the lower half. It is recommended that all Figure
Windows be closed before proceeding to the next example. Subsequent plots
would replace the graph in the lower display region only, or in other words,
the last generated graph in a Figure Window. Alternatively, the command
clf
clears the current i gure. h is command can be used in larger MATLAB
scripts at er using the function
subplot
for multiple plots in a Figure Window.
An important modii cation to graphics is the scaling of the axis. By default,
MATLAB uses axis limits close to the minima and maxima of the data.
Using the command
axis
, however, allows the scale settings to be changed.
h e syntax for this command is simply
axis([xmin xmax ymin ymax])
. h e
command
plot(x,y1,'r--')
axis([0 pi -1 1])
sets the limits of the
x
-axis to 0 and ˀ, whereas the limits of the
y
-axis are set
to the default values -1 and +1. Important options of
axis
are
plot(x,y1,'r--')
axis square
which makes the
x
-axis and
y
-axis the same length, and
plot(x,y1,'r--')
axis equal
which makes the individual tick mark increments on the
x
-axis and
y
-axis
the same length. h e function
grid
adds a grid to the current plot, whereas
the functions
title
,
xlabel
and
ylabel
allow a title to be dei ned and labels to
be applied to the
x
- and
y
-axes.
plot(x,y1,'r--')
title('My first plot')
xlabel('x-axis')
ylabel('y-axis')
grid
h ese are a few examples how MATLAB functions can be used to edit the
plot in the Command Window. More graphics functions will be introduced