4

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.

Amro
  • 123,847
  • 25
  • 243
  • 454
user1919235
  • 470
  • 7
  • 17

1 Answers1

0

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!
danny
  • 306
  • 1
  • 6
  • As far as I understand the Position property does not include the tick marks, labels, title, and axis labels (see [http://www.mathworks.ch/ch/help/matlab/creating_plots/automatic-axes-resize.html](http://www.mathworks.ch/ch/help/matlab/creating_plots/automatic-axes-resize.html)). – user1919235 Oct 11 '14 at 10:29
  • Try my edited response, should do what you want. – danny Oct 11 '14 at 10:37
  • I am sorry, but I do not understand your answer. What I want to know is the amount of space that the color bar takes up, including the tick marks, labels, titles, and axis labels. So I would expect an answer of the form width = ... and height = ... – user1919235 Oct 11 '14 at 10:47
  • @user1919235 The 2 last values in `get(c, 'Position')` are width and height. Calling the `Position` property results in 4 element array `[x y width height]`. Is it answers your question? – EBH Jul 04 '16 at 18:49