MATLAB Programming/Axis Handle

MATLAB offers incomparable control over the way you can add details to your plot. From inserting text at the right positions to labelling the axes, MATLAB from the command line offers you an easy way to create publication style graphics. With support for Encapsulated PostScript and Adobe Illustrator output. Complex figures with several axes and conveying large amounts of information can be created.

Concept of a handle edit

Most operations on figures generate objects with a set of properties. Users familiar with object-oriented programming would realize that the functions and the data are encapsulated into the object. A typical figure would contain at least half a dozen objects. These objects are called handles. A very tacky analogy would be like handles to several different refrigerators with several different contents. To provide an intuitive feel. I have listed out the properties from a text handle.

Finding a handle edit

Various commands provide required handles, for example:

h = gcf; % Get current figure
h = gca; % Get current axis

Examples edit

Axis Label edit

xlabel labels the x-axis of the current plot.


You can display text on two lines or insert the value of variables

xlabel({['First Line or line n° ',int2str(a)],['Second Line or line n°',int2str(b)]})

ylabel labels the y-axis of the current plot. It works in same way of xlabel, but the output is vertical in 2D plots.

Documenting a Maximum Value edit

% Previous code set the x value of the peak data point into x_peak 
ptitle = 'UUT and Source Correlation Score Magnitude'; 
xlabel('Lag'); ylabel('Correlation Magnitude'); 
title(ptitle); yloc = max(get(gca,'YLim')); 
% Put at top of plot 
text(lags(x_peak),yloc,[' \leftarrow ' num2str(x_peak) 'ns']);
lstr{1} = sprintf(' Test %d', TESTNUM); lstr{2} = sprintf(' Unit %d%s', UNITNUM, comparestr);