Plot Objects

Introduction

A number of high-level plotting functions create plot objects. The properties of plot objects provide easy access to the important properties of the core graphics objects that the plot objects contain.

Plot object parents can be axes or group objects (hggroup or hgtransform). See Objects That Can Contain Other Objects for examples.

This table lists the plot objects and the graphing functions that use them. Click object names to see a description of their properties.

Plot Objects

Object

Purpose

areaseries

Used to create area graphs

barseries

Used to create bar graphs

contourgroup

Used to create contour graphs

errorbarseries

Used to create errorbar graphs

lineseries

Used by line plotting functions (plot, plot3, etc.)

quivergroup

Used to create quiver and quiver3 graphs

scattergroup

Used to create scatter and scatter3 graphs

stairseries

Used to create stairstep graphs (stairs)

stemseries

Used to create stem and stem3 graphs

surfaceplot

Used by the surf and mesh group of functions

Creating a Plot Object

For example, the following statements create a contour graph of the peaks function and then set the line style and width of the contour lines.

[x,y,z] = peaks;
[c,h] = contour(x,y,z);
set(h,'LineWidth',3,'LineStyle',':')

The contour plot object enables you to set the line width and style of the contour graph by setting two properties. Looking at the core objects contained in the contour plot object reveals a number of patch objects whose edges are used to implement the contour line, which you would otherwise need to set individually.

child_handles = get(h,'Children');
get(child_handles,'Type')
ans = 
    'patch'
    'patch'
    'patch'
    'patch'
    'patch'
    'patch'
    'patch'
    'patch'
    'patch'
    'patch'
    'patch'
    'patch'

Identifying Plot Objects Programmatically

Plot objects all return hggroup as the value of the Type property. If you want to be able to identify plot objects programmatically but do not have access to the object's handle, set a value for the object's Tag property.

For example, the following statements create a bar graph with five barseries objects and assign a different value for the Tag property on each object.

h = bar(rand(5));
set(h,{'Tag'},{'bar1','bar2','bar3','bar4','bar5'}')

Note that the cell array of property values must be transposed (') to have the proper shape. See the set function for more information on setting properties.

No User Default Values

Note that you cannot define default values for plot objects.

Plot Objects and Backward Compatibility

Plotting functions that create plot objects can introduce incompatibilities with code written before MATLAB Version 7.x. However, all plotting functions that return handles to plot objects support an optional argument ('v6') that forces the functions to use core objects, as was the case in MATLAB software before Version 7.

Saving Figures That Are Compatible with Previous Version of MATLAB®

Create backward-compatible FIG-files by following these two steps.

For example,

h = figure;
t = 0:pi/20:2*pi;
plot('v6',t,sin(t).*2)
hgsave(h,'myFigFile','-v6')

You can set a general MATLAB preference to ensure that figures saved by selecting the Save item under the figure File menu are backward compatible. To access MATLAB preferences, select Preferences from the Desktop File menu. Expand the General node and select MAT Files. Click Ensure backward compatibility (-v6). Note that this setting affects all FIG-files and MAT-files that you create.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS