Documentation Center

  • Trial Software
  • Product Updates

Change Colorbar Width

This example shows how to change the width of the colorbar by setting its Position property. The Position property sets the location and size of the colorbar. Specify the Position property value as a four-element vector of the form [left,bottom,width,height], where the first two elements set the colorbar position relative to the figure, and the last two elements set its size.

Create a checkerboard plot of the peaks function and add a colorbar.

c = colorbar;

Store the current positions of the axes and the colorbar.

axpos = get(gca,'Position');
cpos = get(c,'Position');

Change colorbar width to half of its original value by adjusting the third element in cpos. Set the colorbar Position property to the updated position vector. Then, reset the axes to its original position so that it does not overlap the colorbar.

cpos(3) = 0.5*cpos(3);

The graph displays a colorbar that has a narrow width.

See Also


Was this topic helpful?