Changing size and position of map colorbar

65 visualizzazioni (ultimi 30 giorni)
Abdul
Abdul il 19 Ott 2016
Commentato: Abdul il 19 Ott 2016
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

Risposte (1)

KSSV
KSSV il 19 Ott 2016
Modificato: KSSV il 19 Ott 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
  1 Commento
Abdul
Abdul il 19 Ott 2016
Thanks for the answer. Yes,I do the same but it does not work and distorts the color bar. Any other suggestion?

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by