Graphics objects represent data in intuitive and meaningful ways, such as line graphs, images, text, and combinations of these objects. Graphics objects act as containers for other objects or as representations of data.
Containers — Figures display all graphics objects. Panels and groups enable collections of objects to be treated as one entity for some operations.
Axes are containers that define a coordinate system for the objects that represent the actual data in graphs.
Data visualization objects — Lines, text, images, surfaces, and patches that implement various types of graphs.
Figures are the windows in which MATLAB® displays graphics. Figures contain menus, toolbars, user-interface objects, context menus, and axes.
Figures play two distinct roles in MATLAB:
Containing graphs of data
Containing user interfaces (which can include graphs in the interface)
Figure properties control certain characteristics that affect graphs:
Figures use different drawing methods called renderers. There are two renderers:
OpenGL® — The default renderer used by MATLAB for most applications. For more information, see
Painters — Use when OpenGL has problems on a computer with particular graphics hardware that has software defects or outdated software drivers. Also used for exporting graphics for certain formats, such as PDF.
For best results, ensure that your computer has the latest graphics hardware drivers supplied by the hardware vendor.
For a list of all figure properties, see Figure Properties
MATLAB creates an axes to define the coordinate system of each graph. Axes are always contained by a figure object. Axes themselves contain the graphics objects that represent data.
Axes control many aspects of how MATLAB displays graphical information.
Much of what you can customize in a graph is controlled by axes properties.
Axis limits, orientation, and tick placement
Axis scales (linear or logarithmic)
Font characteristics for the title and axis labels.
Default line colors and line styles for multiline graphs
Axis line and grid control
Color scaling of objects based on colormap
View and aspect ratio
Clipping graphs to axis limits
Controlling axes resize behavior
Lighting and transparency control
For a list of all axes properties, see Axes Properties
Data objects are the lines, images, text, and polygons that graphs use to represent data. For example:
Lines connect data points using specified x- and y-coordinates.
Markers locate scattered data in some range of values.
Rectangular bars indicate distribution of values in a histogram.
Because there are many kinds of graphs, there are many types of data objects. Some are general purpose, such as lines and rectangles and some are highly specialized, such as errorbars, colorbars, and legends.
Data object properties control the appearance of the object and also contain the data that defines the object. Data object properties can also control certain behaviors.
Data — Change the data to update the graph. Many data objects can link their data properties to workspace variables that contain the data.
Color Data — Objects can control how data maps to colors by specifying color data.
Appearance — Specify colors of line, markers, polygon faces as well as line styles, marker types.
Specific behaviors — Properties can control how the object interprets or
displays its data. For example, Bar objects have a property called
BarLayout that determines if the bars are grouped or stacked.
Contour objects have a
LevelList property that
specifies the contour intervals at which to draw contour lines.
Plotting functions create data objects in one of two ways:
High-level functions — Create complete graphs that replace existing graphs
with new ones. High-level functions include
scatter, and so on. For a summary of
high-level functions, see Types of MATLAB Plots.
Group objects enable you to treat a number of data objects as one entity. For example, you can make the entire group visible or invisible, select all objects when only one is clicked, or apply a transform matrix to rotate, translate, or scale all the objects in the group.
This code parents the plotted lines to the group object returned by the
hggroup function. The text object is not part of the group.
y = magic(5); hg = hggroup; plot(y,'Parent',hg) text(2.5,10,'Plot of 5x5 magic square')
Annotation objects comprise arrows, text boxes, and combinations of both. Annotation objects have special features that overcome the limitations of data objects used to annotate graphs:
Annotation objects are children of the figure.
You can easily locate annotations anywhere in the figure.
Define the location of annotation objects in normalized figure coordinates: lower left = (0,0), upper right = (1,1), making their placement independent of range of data represented by the axes.
MATLAB parents annotation objects to a special layer. Do not attempt to parent objects to this layer. MATLAB automatically assigns annotation objects to the appropriate parent.