colorbar ticklabel location set up
47 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Star Strider
on 21 Sep 2014
Edited: Star Strider
on 21 Sep 2014
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
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?
More Answers (1)
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
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.
See Also
Categories
Find more on Colormaps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!