Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
colorbar position: please try this code

Subject: colorbar position: please try this code

From: David Epstein

Date: 10 Apr, 2012 06:16:24

Message: 1 of 2

%% Code suggested by Steve Lord of Mathworks.
colormap([1 1 1;1 0 0; 0 1 0; 0 0 1; 0 0 0]);
x = randi([1 5], [7 7]);
image(x, 'CDataMapping', 'direct')
h = colorbar;
set(h, 'YTick', 1:5, 'YTickLabel', {'Object 1', 'Object 2', 'Object 3',...
'Object 4', 'Object 5'});

%% Now execute these two lines (my addition to Steve Lord's code)
cbPos=get(h,'Position');
set(h,'Position',cbPos);

In my version of Matlab (2011a under MacOsX 10.6.8), the final two lines change the position of the colorbar. Should this happen? Does it happen with a more recent version of Matlab? On other platforms?

Subject: colorbar position: please try this code

From: ZoƩ

Date: 15 Apr, 2013 13:31:07

Message: 2 of 2

"David Epstein" <David.Epstein.spam@remove.warwick.ac.uk> wrote in message <jm0j7o$hpe$1@newscl01ah.mathworks.com>...
> %% Code suggested by Steve Lord of Mathworks.
> colormap([1 1 1;1 0 0; 0 1 0; 0 0 1; 0 0 0]);
> x = randi([1 5], [7 7]);
> image(x, 'CDataMapping', 'direct')
> h = colorbar;
> set(h, 'YTick', 1:5, 'YTickLabel', {'Object 1', 'Object 2', 'Object 3',...
> 'Object 4', 'Object 5'});
>
> %% Now execute these two lines (my addition to Steve Lord's code)
> cbPos=get(h,'Position');
> set(h,'Position',cbPos);
>
> In my version of Matlab (2011a under MacOsX 10.6.8), the final two lines change the position of the colorbar. Should this happen? Does it happen with a more recent version of Matlab? On other platforms?

I am not sure whether this is what is supposed to happen. To me, the behavior seems strange, but maybe you can file a service request at the MathWorks to see whether they can come up with a reasonable explanation.

As far as your questions about the platform and Matlab version are concerned, I can confirm that the color bar also moves when using Matlab R2013a under Windows 7.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us