This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Why Are Colorbars and Legends Not Valid Axes Handles?

Starting in R2014b, colorbars and legends are no longer axes objects. They are new types of objects that have their own sets of supported properties. In previous releases, they are axes objects that you can modify using axes properties. However, many axes properties are not relevant to colorbars and legends.

You should not perform operations that assume or require colorbars and legends to be axes objects.

Use Supported Colorbar and Legend Properties

Do not use axes properties to modify colorbars or legends. Use their supported properties. For a list, see ColorBar Properties or Legend Properties.

For example, to reverse the direction of the color scale along a colorbar use the new Direction property for the colorbar instead of setting the XDir or YDir axes property.

c = colorbar;
c.Direction = 'reverse';

Colorbars and Legends Cannot Be Current Axes

Do not pass a colorbar object or a legend object to a function that expects an axes object as an input argument.

For example, passing a legend object to the axes function to make it the current axes returns an error message:

plot(1:10)
l = legend('line plot');
axes(l)
Error using axes
Handles of type Legend cannot be made the current Axes.

Similarly, passing a colorbar object to the axes function returns an error message:

c = colorbar;
axes(c)
Error using axes
Handles of type ColorBar cannot be made the current Axes.
In previous releases, you might make a colorbar the current axes before giving it a title, Now, use the new Label property of the colorbar instead.
c = colorbar;
c.Label.String = 'Colorbar Label';

Find Objects Using New Type Property Values

Colorbars and legends no longer have a Type property of 'axes'. Do not use findall or findobj to find objects with a Type property of 'axes' and expect it to return colorbars and legends.

To find legends, search for objects with a Type property of 'legend'.

findall(groot,'Type','legend')

To find colorbars, search for objects with a Type property of 'colorbar'.

findall(groot,'Type','colorbar')

Colorbars and Legends Have No Children

Colorbars and legends no longer contain handles to underlying objects in their Children property. Their Children properties contain an empty graphics placeholder array. For a legend, access these underlying objects using the output arguments from the legend function instead.

See Also

Functions

Properties