Changing size and position of map colorbar
68 views (last 30 days)
Show older comments
Hi, I want to change the size and position of my map colorbar. When I try to change the size and location of the colorbar, it is distorted in shape, I don't know why. Can anybody kindly help me. Please guide me why the set command distorts the clorbar? The location of the color bar should be 'southoutside'.The code is as under:
clear all,close all,clc
ax = worldmap('world');
load geoid
R = georasterref('RasterSize',[180 360],'Latlim',[-90 90],'Lonlim', [0 360]);
levels = [-70 -40 -20 -10 0 10 20 40 70];
geoshow(geoid, R, 'DisplayType', 'contour','LevelList',levels,'Fill','on','LineColor','black')
coast = load('coast.mat');
geoshow(coast.lat, coast.long, 'Color', 'white', 'LineWidth', 1.5)
cb = contourcbar('peer',ax,'Location','southoutside');
caxis([-110 90])
colormap(hsv)
set(get(cb,'XLabel'),'String','Geoid Undulation in Meters')
a=get(cb); %gets properties of colorbar
a.Position %gets the positon and size of the color bar
set(cb,'Position',[0.10 0.20 0.70 0.05])% To change size
0 Comments
Answers (1)
KSSV
on 19 Oct 2016
Edited: KSSV
on 19 Oct 2016
a.position returns you a 1x4 array. Which represents [left,bottom,width,height]. You can change first two numbers to change the position, change third number for width and fourth for height.
a = a.Position %gets the positon and size of the color bar
set(cb,'Position',[a(1)+dx a(2)+dy w h])% To change size
you adjust dx,dy to move the color bar....adjust w, h for it's size.
Eg:
set(cb,'Position',[a(1) a(2) 0.70 0.03])
places the colorbar at the same position with width 0.7 and height 0.03
See Also
Categories
Find more on Mapping Toolbox 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!