Documentation Center

  • Trial Software
  • Product Updates

Colors Controlled by Axes

Introduction

Axes properties specify the color of the axis lines, tick marks, labels, and the background. Properties also control the colors of the lines drawn by plotting routines and how image, patch, and surface objects obtain colors from the figure colormap.

The axes properties discussed in this section are listed in the following table.

Property

Characteristic it Controls

Color

Axes background color

XColor, YColor, ZColor

Color of the axis lines, tick marks, gridlines, and labels

Title

Title text object handles

XLabel, YLabel, Zlabel

Axis label text object handles

CLim

Controls mapping of graphic object CData to the figure colormap

CLimMode

Automatic or manual control of CLim property

ColorOrder

Line color autocycle order

LineStyleOrder

Line styles autocycle order (not a color, but related to ColorOrder)

Specifying Axes Colors

The default axes background color is set up by the colordef command, which is called in your startup file. However, you can easily define your own color scheme.

Changing the Color Scheme

Suppose you want an axes to use a "black-on-white" color scheme. First, change the background to white and the axis lines, grid, tick marks, and tick mark labels to black.

set(gca,'Color','w',...
        'XColor','k',...
        'YColor','k',...
        'ZColor','k')

Next, change the color of the text objects used for the title and axis labels.

set(get(gca,'Title'),'Color','k')
set(get(gca,'XLabel'),'Color','k')
set(get(gca,'YLabel'),'Color','k')
set(get(gca,'ZLabel'),'Color','k')

Changing the figure background color to white completes the new color scheme.

set(gcf,'Color','w')

When you are done, a figure containing a mesh plot looks like the following figure.

You can define default values for the appropriate properties and put these definitions in your startup.m file. Titles and axis labels are text objects, so you must set a default color for all text objects, which is a good idea anyway because the default text color of white is not visible on the white background. Lines created with the low-level line function (but not the plotting routines) also have a default color of white, so you should change the default line color as well.

To set default values on the root level, use

set(0,'DefaultFigureColor','w'
      'DefaultAxesColor','w',...
      'DefaultAxesXColor','k',...
      'DefaultAxesYColor','k',...
      'DefaultAxesZColor','k',...
      'DefaultTextColor','k',...
      'DefaultLineColor','k')

The MATLAB® software colors other axes children (i.e., image, patch, and surface objects) according to the values of their CData properties and the figure colormap.

Was this topic helpful?