Next: , Previous: , Up: High-Level Plotting   [Contents][Index]


15.2.3 Plot Annotations

You can add titles, axis labels, legends, and arbitrary text to an existing plot. For example:

x = -10:0.1:10;
plot (x, sin (x));
title ("sin(x) for x = -10:0.1:10");
xlabel ("x");
ylabel ("sin (x)");
text (pi, 0.7, "arbitrary text");
legend ("sin (x)");

The functions grid and box may also be used to add grid and border lines to the plot. By default, the grid is off and the border lines are on.

Function File: title (string)
Function File: title (string, prop, val, …)
Function File: title (hax, …)
Function File: h = title (…)

Specify the string used as a title for the current axis.

An optional list of property/value pairs can be used to change the appearance of the created title text object.

If the first argument hax is an axes handle, then plot into this axis, rather than the current axes returned by gca.

The optional return value h is a graphics handle to the created text object.

See also: xlabel, ylabel, zlabel, text.

Function File: legend (str1, str2, …)
Function File: legend (matstr)
Function File: legend (cellstr)
Function File: legend (…, "location", pos)
Function File: legend (…, "orientation", orient)
Function File: legend (hax, …)
Function File: legend (hobjs, …)
Function File: legend (hax, hobjs, …)
Function File: legend ("option")
Function File: [hleg, hleg_obj, hplot, labels] = legend (…)

Display a legend for the current axes using the specified strings as labels.

Legend entries may be specified as individual character string arguments, a character array, or a cell array of character strings.

If the first argument hax is an axes handle, then plot into this axis, rather than the current axes returned by gca. If the handles, hobjs, are not specified then the legend’s strings will be associated with the axes’ descendants. legend works on line graphs, bar graphs, etc. A plot must exist before legend is called.

The optional parameter pos specifies the location of the legend as follows:

poslocation of the legend
northcenter top
southcenter bottom
eastright center
westleft center
northeastright top (default)
northwestleft top
southeastright bottom
southwestleft bottom
outsidecan be appended to any location string

The optional parameter orient determines if the key elements are placed vertically or horizontally. The allowed values are "vertical" (default) or "horizontal".

The following customizations are available using option:

"show"

Show legend on the plot

"hide"

Hide legend on the plot

"toggle"

Toggles between "hide" and "show"

"boxon"

Show a box around legend (default)

"boxoff"

Hide the box around legend

"right"

Place label text to the right of the keys (default)

"left"

Place label text to the left of the keys

"off"

Delete the legend object

The optional output values are

hleg

The graphics handle of the legend object.

hleg_obj

Graphics handles to the text and line objects which make up the legend.

hplot

Graphics handles to the plot objects which were used in making the legend.

labels

A cell array of strings of the labels in the legend.

The legend label text is either provided in the call to legend or is taken from the DisplayName property of graphics objects. If no labels or DisplayNames are available, then the label text is simply "data1", "data2", …, "dataN".

Implementation Note: A legend is implemented as an additional axes object of the current figure with the "tag" set to "legend". Properties of the legend object may be manipulated directly by using set.

Function File: text (x, y, string)
Function File: text (x, y, z, string)
Function File: text (…, prop, val, …)
Function File: h = text (…)

Create a text object with text string at position x, y, (z) on the current axes.

Multiple locations can be specified if x, y, (z) are vectors. Multiple strings can be specified with a character matrix or a cell array of strings.

Optional property/value pairs may be used to control the appearance of the text.

The optional return value h is a vector of graphics handles to the created text objects.

See also: gtext, title, xlabel, ylabel, zlabel.

See Text Properties for the properties that you can set.

Function File: xlabel (string)
Function File: xlabel (string, property, val, …)
Function File: xlabel (hax, …)
Function File: h = xlabel (…)

Specify the string used to label the x-axis of the current axis.

An optional list of property/value pairs can be used to change the properties of the created text label.

If the first argument hax is an axes handle, then operate on this axis rather than the current axes returned by gca.

The optional return value h is a graphics handle to the created text object.

See also: ylabel, zlabel, datetick, title, text.

Function File: clabel (c, h)
Function File: clabel (c, h, v)
Function File: clabel (c, h, "manual")
Function File: clabel (c)
Function File: clabel (…, prop, val, …)
Function File: h = clabel (…)

Add labels to the contours of a contour plot.

The contour levels are specified by the contour matrix c which is returned by contour, contourc, contourf, and contour3. Contour labels are rotated to match the local line orientation and centered on the line. The position of labels along the contour line is chosen randomly.

If the argument h is a handle to a contour group object, then label this plot rather than the one in the current axes returned by gca.

By default, all contours are labeled. However, the contours to label can be specified by the vector v. If the "manual" argument is given then the contours to label can be selected with the mouse.

Additional property/value pairs that are valid properties of text objects can be given and are passed to the underlying text objects. Moreover, the contour group property "LabelSpacing" is available which determines the spacing between labels on a contour to be specified. The default is 144 points, or 2 inches.

The optional return value h is a vector of graphics handles to the text objects representing each label. The "userdata" property of the text objects contains the numerical value of the contour label.

An example of the use of clabel is

[c, h] = contour (peaks (), -4 : 6);
clabel (c, h, -4:2:6, "fontsize", 12);

See also: contour, contourf, contour3, meshc, surfc, text.

Command: box on
Command: box off
Command: box
Function File: box (hax, …)

Control display of the axis border.

The argument may be either "on" or "off". If it is omitted, the current box state is toggled.

If the first argument hax is an axes handle, then operate on this axis rather than the current axes returned by gca.

See also: axis, grid.

Command: grid
Command: grid on
Command: grid off
Command: grid minor
Command: grid minor on
Command: grid minor off
Function File: grid (hax, …)

Control the display of plot grid lines.

The function state input may be either "on" or "off". If it is omitted, the current grid state is toggled.

When the first argument is "minor" all subsequent commands modify the minor grid rather than the major grid.

If the first argument hax is an axes handle, then operate on this axis rather than the current axes returned by gca.

To control the grid lines for an individual axis use the set function. For example:

set (gca, "ygrid", "on");

See also: axis, box.

Command: colorbar
Function File: colorbar (loc)
Function File: colorbar (delete_option)
Function File: colorbar (hcb, …)
Function File: colorbar (hax, …)
Function File: colorbar (…, "peer", hax, …)
Function File: colorbar (…, "location", loc, …)
Function File: colorbar (…, prop, val, …)
Function File: h = colorbar (…)

Add a colorbar to the current axes.

A colorbar displays the current colormap along with numerical rulings so that the color scale can be interpreted.

The optional input loc determines the location of the colorbar. Valid values for loc are

"EastOutside"

Place the colorbar outside the plot to the right. This is the default.

"East"

Place the colorbar inside the plot to the right.

"WestOutside"

Place the colorbar outside the plot to the left.

"West"

Place the colorbar inside the plot to the left.

"NorthOutside"

Place the colorbar above the plot.

"North"

Place the colorbar at the top of the plot.

"SouthOutside"

Place the colorbar under the plot.

"South"

Place the colorbar at the bottom of the plot.

To remove a colorbar from a plot use any one of the following keywords for the delete_option: "delete", "hide", "off".

If the argument "peer" is given, then the following argument is treated as the axes handle in which to add the colorbar. Alternatively, If the first argument hax is an axes handle, then the colorbar is added to this axis, rather than the current axes returned by gca.

If the first argument hcb is a handle to a colorbar object, then operate on this colorbar directly.

Additional property/value pairs are passed directly to the underlying axes object.

The optional return value h is a graphics handle to the created colorbar object.

Implementation Note: A colorbar is created as an additional axes to the current figure with the "tag" property set to "colorbar". The created axes object has the extra property "location" which controls the positioning of the colorbar.

See also: colormap.


Next: , Previous: , Up: High-Level Plotting   [Contents][Index]