www.gusucode.com > graphics 案例源码程序 matlab代码 > graphics/ChangeColorbarWidthExample.m
%% 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. figure pcolor(peaks) c = colorbar; %% % Store the current positions of the axes and the colorbar. % % *Note:* Starting in R2014b, you can use dot notation to set properties. % If you are using an earlier release, use the % <docid:matlab_ref.f58-517463> and <docid:matlab_ref.f67-432995> functions % instead, such as |axpos = get(ax,'Position')|. ax = gca; axpos = ax.Position; cpos = c.Position; %% % Change the colorbar width to half of its original width 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); c.Position = cpos; ax.Position = axpos; %% % The graph displays a colorbar that has a narrow width.