colorbar ticklabel location set up

47 views (last 30 days)
Leon
Leon on 21 Sep 2014
Commented: Adam on 27 Mar 2017
The default setting put the ticklabel to the left side the colorbar. How do I set it up so that it will appear to the right side of the colorbar?
Thank you.

Accepted Answer

Star Strider
Star Strider on 21 Sep 2014
Edited: Star Strider on 21 Sep 2014
For details, see the documentation on colorbar and Axis Properties.
Shamelessly ripping the relevant parts of this example code directly from that documentation, you can position the labels on whatever side of the colorbar you want:
x = -5:0.1:5;
[X,Y] = meshgrid(x);
Z = X.^2 - Y.^2;
figure(1)
surf(X, Y, Z)
grid on
colorbar('EastOutside')
figure_handle = gcf;
cbar_handle = findobj(figure_handle,'tag','Colorbar')
set(cbar_handle, 'YAxisLocation','right')
Experiment with 'YAxisLocation','right' and 'YAxisLocation','right' to see the effect.
  6 Comments
Leon
Leon on 21 Sep 2014
Edited: Leon on 21 Sep 2014
Thank you for the reply!
Unfortunately, it still does not work, as long as I keep the set 'position' statement.
BTW, the ticklabel was in the right side just as I want it to be, before I added the below statement to change the colormap to something new.
load ('color1.mat');
colormap(cmap);
Star Strider
Star Strider on 21 Sep 2014
Edited: Star Strider on 21 Sep 2014
My pleasure!
1. Combine the 'Position' in with the other commands in my:
set(cbar_handle, ...
as you did the others, or alternatively, create a second ‘set(cbar_handle, ...’ line with additional options and settings. Use the same cbar_handle variable as your handle to the colorbar.
2. It seems that when you do the load, it is loading variables into your workspace that are overriding your other settings. Load your colormap variable first.
3. It may be necessary for you to attach your entire code (use the ‘paperclip’ icon) and we’ll see if we can sort this. (No promises.) What are you loading with the load call? Where in your code are you loading it?

Sign in to comment.

More Answers (1)

Gaby MayorgaAdame
Gaby MayorgaAdame on 27 Mar 2017
The labels of my colorbar appear to the left and I can't move them to the right. This is what I tried and what I got: >> figure_handle = gcf; >> cbar_handle = findobj(figure_handle,'tag','Colorbar')
cbar_handle =
ColorBar (Colorbar) with properties:
Location: 'manual'
Limits: [0 20]
FontSize: 15
Position: [0.9286 0.0976 0.0249 0.8143]
Units: 'normalized'
Show all properties
>> set(cbar_handle, 'YAxisLocation','right') Warning: Error updating ColorBar. Following is the chain of causes of the error:
While setting the 'AxisLocation' property of ColorBar:
'outt' is not a valid value. Use one of these values: 'in' | 'out'.
  1 Comment
Adam
Adam on 27 Mar 2017
Please start a new question rather than adding an answer to an existing question which already has an accepted answer. It is more likely to get attention and an answer suited to your problem and may also help others with a similar problem to yours in the future.

Sign in to comment.

Categories

Find more on Colormaps in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!