Function Reference
— Function File: colorbar (s)
— Function File: colorbar ('peer', h, ...)

Adds a colorbar to the current axes. Valid values for s 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.
'Off', 'None'
Remove any existing colorbar from the plot.

If the argument 'peer' is given, then the following argument is treated as the axes handle on which to add the colorbar.

Demonstration 1

The following code

 hold off;
 close all;
 n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 imagesc(x)
 colorbar();

Produces the following figure

Demonstration 2

The following code

 hold off;
 n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 imagesc(x)
 colorbar("westoutside");

Produces the following figure

Demonstration 3

The following code

 hold off;
 n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 imagesc(x)
 colorbar("northoutside");

Produces the following figure

Demonstration 4

The following code

 hold off;
 n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); 
 imagesc(x)
 colorbar("southoutside");

Produces the following figure

Demonstration 5

The following code

 hold off;
 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

Demonstration 6

The following code

 hold off;
 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

Demonstration 7

The following code

 hold off;
 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

Demonstration 8

The following code

 hold off;
 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

Demonstration 9

The following code

 hold off;
 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

Demonstration 10

The following code

 hold off;
 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

Demonstration 11

The following code

 hold off;
 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

Demonstration 12

The following code

 hold off;
 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

Demonstration 13

The following code

 hold off;
 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

Demonstration 14

The following code

 hold off;
 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