MATLAB Answers

Title on the colour bar and legend issues

2 views (last 30 days)
charlotte jennings
charlotte jennings on 7 Apr 2020
Answered: darova on 7 Apr 2020
Okay so first of all, ive put a title on my colour bar using this
o= colorbar;
set(get(o,'label'),'string','Change in SST (°C)', 'Rotation',270.0);
which works fine, but the colour bar title is now ontop of the colour bar, is there a way to shift it a few cm to the right of the colour bar. i dont want it facing the otherway as this is part of a panneled figure
My second issue is my legend. ive plotted 3 things, but i only want 2 of the points to be in my figure legend. i just want the legend to show a red point for lon_track14 and a black point for lon_Track. at the moment when you click legend on the figure itself it is labeling every indicule data point
figure
pcolour (lon,lat,Diff'); %i dont want this in my legend
shading flat
hold on
forip=1:np
[lat_temp,lon_temp]=utm2ll(xsave(ip,:),ysave(ip,:)utmzone);
lat_track(ip,:)=lat_temp;
lon_track(ip,:)=lon_temp;
plot(lon_track14,lat_track14, '.R'); % i want this in my legend to be a red point saying 2014
hold on
plot(lon_track,lat_track, '.-K'); % I wan this in my lened
end

  0 Comments

Sign in to comment.

Answers (2)

Geoff Hayes
Geoff Hayes on 7 Apr 2020
charlotte - you might be able to set the Position property of the label. To check the current position, you could try
hLabel = get(o,'label');
currentPos = get(hLabel, 'Position');
cuurentPos(1) = currentPos(1) + 1.23; % 1.23 is just an example
set(hLabel, 'Position', cuurentPos);
Try using the current position and just modify the x coordinate to something else so that the labels moves to the right.
As for the legend problem, I think that it is going to add every plot to the legend. Since on every iteration of your for loop, you are creating two plot graphics objects, then there will be npx2 plots added to your legend. You could try to change your code so that you plot after you have done the iterations:
for ip=1:np
[lat_temp,lon_temp]=utm2ll(xsave(ip,:),ysave(ip,:)utmzone);
lat_track(ip,:)=lat_temp;
lon_track(ip,:)=lon_temp;
end
plot(lon_track14,lat_track14, '.R'); % i want this in my legend to be a red point saying 2014
hold on
plot(lon_track,lat_track, '.-K'); % I wan this in my lened

  0 Comments

Sign in to comment.


darova
darova on 7 Apr 2020
Use handlers to add specific string to legend
pcolor()
hold on
h1 = plot();
h2 = plot();
hold off
legend([h1 h2],'red','black')
  • colorbar
Can't you just add some space isnide string?
'Change in SST (°C) '

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products


Release

R2019b

Translated by