Problems with legend using imagesc

I have the following code, I have adapted it from another code and I think that is where I am getting stuck.
basically I have a 35x43 matrix of numbers 1-6 and NaNs. I want to plot is as a map using imagesc with different colours for each number (1,2,3,4,5,6). I have attached the data, and my code is below.
Thanks in advance for any help
figure(6)
subplot(1,2,1)
imagesc(lut)
title('Distribution of Different Land Use Types in Australia')
ylabel('Longitude')
xlabel('Latitude')
caxis([0, 6])
myColorMap = jet(6);
myColorMap(1,:) = 1;
colormap(myColorMap);
M = jet(6);
hold on
L = line(ones(6),ones(6));
set(L,{'color'},mat2cell(M,ones(1,6),3))
[legh,objh,outh,outm] = legend('First','Second','Location','Southeast');
set(objh,'linewidth',200);
legend(1,'Forest',2,'Shrubland',3,'Savanna',4,'Grassland',5,'Agricultural',6,'Barron');
grid on
ax = gca
ax.GridAlpha = .2
ax.XTick = [5 10 15 20 25 30 35 40];
ax.YTick = [5 10 15 20 25 30];
ax.XTickLabel = {'118^{o}E','123^{o}E','128^{o}E', '133^{o}E', '138^{o}E', '143^{o}E','148^{o}E', '153^{o}E'};
ax.YTickLabel = {'13^{o}S','18^{o}S','23^{o}S','28^{o}S','33^{o}S','38^{o}S'};
ax.TickLength =[0.0 0.0]

回答 (1 件)

KSSV
KSSV 2016 年 10 月 4 日

0 投票

Replace
legend(1,'Forest',2,'Shrubland',3,'Savanna',4,'Grassland',5,'Agricultural',6,'Barron');
with
legend('Forest' ,'Shrubland', 'Savanna','Grassland' , 'Agricultural' ,'Barron');

6 件のコメント

Robert
Robert 2016 年 10 月 4 日
Thank you for your answer, but this doesn't solve the problem
KSSV
KSSV 2016 年 10 月 4 日
what is problem?
Robert
Robert 2016 年 10 月 4 日
The problem is that the colours in the legend don't match the colours in the image. See attached picture as an example. The large light blue area is all shrubland, however the legend shows it as savanna, this is a problem for all the different variables.
Robert
Robert 2016 年 10 月 4 日
here is the attachment
KSSV
KSSV 2016 年 10 月 4 日
Try
image(lut)
instead
imagesc(lut)
Robert
Robert 2016 年 10 月 4 日
This does not fix the problem either.
I am pretty sure the answer lies within these lines
caxis([0, 6])
myColorMap = jet(6);
myColorMap(1,:) = 1;
colormap(myColorMap);
M = jet(6);
hold on
L = line(ones(6),ones(6));
set(L,{'color'},mat2cell(M,ones(1,6),3))
I have tried various combinations of numbers but with no luck...

サインインしてコメントする。

カテゴリ

製品

タグ

質問済み:

2016 年 10 月 4 日

コメント済み:

2016 年 10 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by