Navigation

Operators and Keywords

Function List:

C++ API

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.

Demonstration 1

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 imagesc (x);
 colorbar ();
 title ('colorbar() example');

Produces the following figure

Figure 1

Demonstration 2

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 imagesc (x);
 colorbar ('westoutside');

Produces the following figure

Figure 1

Demonstration 3

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 imagesc (x);
 colorbar ('peer', gca, 'northoutside');

Produces the following figure

Figure 1

Demonstration 4

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 imagesc (x);
 colorbar ('southoutside');

Produces the following figure

Figure 1

Demonstration 5

The following code

 clf;
 colormap ('default');
 contour (peaks ());
 colorbar ('west');

Produces the following figure

Figure 1

Demonstration 6

The following code

 clf;
 colormap ('default');
 subplot (2,2,1);
  contour (peaks ());
  colorbar ('east');
 subplot (2,2,2);
  contour (peaks ());
  colorbar ('west');
 subplot (2,2,3);
  contour (peaks ());
  colorbar ('north');
 subplot (2,2,4);
  contour (peaks ());
  colorbar ('south');

Produces the following figure

Figure 1

Demonstration 7

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (2,2,1);
  imagesc (x);
  colorbar ();
 subplot (2,2,2);
  imagesc (x);
  colorbar ('westoutside');
 subplot (2,2,3);
  imagesc (x);
  colorbar ('northoutside');
 subplot (2,2,4);
  imagesc (x);
  colorbar ('southoutside');

Produces the following figure

Figure 1

Demonstration 8

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (1,2,1);
  imagesc (x);
  axis square;
  colorbar ();
 subplot (1,2,2);
  imagesc (x);
  axis square;
  colorbar ('westoutside');

Produces the following figure

Figure 1

Demonstration 9

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (1,2,1);
  imagesc (x);
  axis square;
  colorbar ('northoutside');
 subplot (1,2,2);
  imagesc (x);
  axis square;
  colorbar ('southoutside');

Produces the following figure

Figure 1

Demonstration 10

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (2,1,1);
  imagesc (x);
  axis square;
  colorbar ();
 subplot (2,1,2);
  imagesc (x);
  axis square;
  colorbar ('westoutside');

Produces the following figure

Figure 1

Demonstration 11

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (2,1,1);
  imagesc (x);
  axis square;
  colorbar ('northoutside');
 subplot (2,1,2);
  imagesc (x);
  axis square;
  colorbar ('southoutside');

Produces the following figure

Figure 1

Demonstration 12

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (1,2,1);
  imagesc (x);
  colorbar ();
 subplot (1,2,2);
  imagesc (x);
  colorbar ('westoutside');

Produces the following figure

Figure 1

Demonstration 13

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (1,2,1);
  imagesc (x);
  colorbar ('northoutside');
 subplot (1,2,2);
  imagesc (x);
  colorbar ('southoutside');

Produces the following figure

Figure 1

Demonstration 14

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (2,1,1);
  imagesc (x);
  colorbar ();
 subplot (2,1,2);
  imagesc (x);
  colorbar ('westoutside');

Produces the following figure

Figure 1

Demonstration 15

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (2,1,1);
  imagesc (x);
  colorbar ('northoutside');
 subplot (2,1,2);
  imagesc (x);
  colorbar ('southoutside');

Produces the following figure

Figure 1

Demonstration 16

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (1,2,1);
  contour (x);
  axis square;
  colorbar ('east');
  xlim ([1, 64]);
  ylim ([1, 64]);
 subplot (1,2,2);
  contour (x);
  colorbar ('west');
  xlim ([1, 64]);
  ylim ([1, 64]);

Produces the following figure

Figure 1

Demonstration 17

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 contour (x);
 xlim ([1, 64]);
 ylim ([1, 64]);
 colorbar ();
 colorbar off;

Produces the following figure

Figure 1

Demonstration 18

The following code

 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 contour (x);
 xlim ([1, 64]);
 ylim ([1, 64]);
 colorbar ();

Produces the following figure

Figure 1

Demonstration 19

The following code

 clf;
 colormap ('default');
 imagesc (1 ./ hilb (99));
 h = colorbar ();
 set (h, 'yscale', 'log');

Produces the following figure

Figure 1

Demonstration 20

The following code

 clf;
 colormap ('default');
 imagesc (log10 (1 ./ hilb (99)));
 h = colorbar ();
 ytick = get (h, 'ytick');
 set (h, 'yticklabel', sprintf ('10^{%g}|', ytick));

Produces the following figure

Figure 1

Demonstration 21

The following code

 clf;
 colormap ('default');
 n = 5; x = linspace (0,5,n); y = linspace (0,1,n);
 imagesc (1 ./ hilb (n));
 axis equal;
 colorbar ();

Produces the following figure

Figure 1

Demonstration 22

The following code

 clf;
 colormap ('default');
 n = 5; x = linspace (0,5,n); y = linspace (0,1,n);
 imagesc (x, y, 1 ./ hilb (n));
 axis equal;
 colorbar ();

Produces the following figure

Figure 1

Demonstration 23

The following code

 clf;
 colormap ('default');
 n = 5; x = linspace (0,5,n); y = linspace (0,1,n);
 imagesc (y, x, 1 ./ hilb (n));
 axis equal;
 colorbar ();

Produces the following figure

Figure 1

Demonstration 24

The following code

 clf;
 colormap ('default');
 axes;
 colorbar ();
 hold on;
 contour (peaks ());
 hold off;

Produces the following figure

Figure 1

Demonstration 25

The following code

 clf;
 colormap ('default');
 plot ([0, 2]);
 colorbar ('east');
 axis square;

Produces the following figure

Figure 1

Demonstration 26

The following code

 clf;
 colormap ('default');
 plot ([0, 2]);
 colorbar ('eastoutside');
 axis square;

Produces the following figure

Figure 1

Demonstration 27

The following code

 clf;
 colormap ('default');
 pcolor (peaks (20));
 shading interp;
 axis ('tight', 'square');
 colorbar ();

Produces the following figure

Figure 1

Demonstration 28

The following code

 clf;
 colormap ('default');
 plot ([0, 2]);
 colorbar ('east');
 axis equal;

Produces the following figure

Figure 1

Demonstration 29

The following code

 clf;
 colormap ('default');
 plot ([0, 2]);
 colorbar ('eastoutside');
 axis equal;

Produces the following figure

Figure 1

Package: octave