How do I find out how much space a color bar takes up using Matlab R2014b? I need to know the total size including all labels, but if I do
c = colorbar;
get(c,'TightInset');
I get the error message
Error using matlab.graphics.illustration.ColorBar/get
There is no TightInset property on the ColorBar class.
The same holds for OuterPosition. Apparently, these properties are no longer supported for the ColorBar class in R2014b.
Try:
original = get(c, 'Position')
set(c, 'Position', [original(1) original(2)*0.5, original(3), original(4)*0.5])
The handle c contains a 'Position' property, same as many graphics handles. Look up the documentation to understand it more fully. To verify that this translates the position of colorbar title and labels too, execute the following:
set(get(c, 'YLabel'), 'String', {'a', 'b', 'c'}) % Arbitrary Labels
set(get(c, 'Title'), 'String', {'Colorbar Title'}); % Arbitrary Title
set(c, 'Position', [original]) % Resize back to original and observe!
来源:https://stackoverflow.com/questions/26313400/size-of-color-bar-including-labels-in-matlab-r2014b