gpt4 book ai didi

matlab - 在图例中平方而不是线条 Matlab

转载 作者:太空宇宙 更新时间:2023-11-03 19:56:35 25 4
gpt4 key购买 nike

Ditribution of Land use Types

我有以下代码,它使用 imagesc 绘制了一个“ map ”,并提供了一个图例,请参阅附件输出。

我正在尝试用实心方 block 替换图例中的线条。我尝试远离线条和广告空心方 block (包括图中左上角的随机方 block )

figure(6)
imagesc(lut)
title('Ditribution of Land use Types')
ylabel('Longitude')
xlabel('Latitude')
caxis([0, 7])
myColorMap = jet(6);

imagesc(lut, 'AlphaData', ~isnan(lut))
colormap(myColorMap);

L = line(ones(6), ones(6));
set(L, {'Color'}, num2cell(myColorMap, 2))

legend(L, {'Forest','Shrubland','Savanna','Grassland','Agricultural','Barron'})
set(L(:),'Marker','s')
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]

最佳答案

使用 nan 创建不可见数据(感谢@matlatbgui),并为无线和填充方形标记设置 L 所需的所有属性:

% some arbitrary data:
N = 30;
lut = diag(1:N)*ones(N)+(diag(1:N)*ones(N)).';

% coloring settings:
caxis([0, 7])
myColorMap = jet(6);

% plotting:
imagesc(lut, 'AlphaData', ~isnan(lut))
colormap(myColorMap);

% Setting the legend:
L = line(nan(6), nan(6),'LineStyle','none'); % 'nan' creates 'invisible' data
set(L, {'MarkerEdgeColor'}, num2cell(myColorMap, 2),...
{'MarkerFaceColor'},num2cell(myColorMap, 2),... % setting the markers to filled squares
'Marker','s');
legend(L, {'Forest','Shrubland','Savanna','Grassland','Agricultural','Barron'})

而且你不需要你的台词:

set(L(:),'Marker','s')

legend

关于matlab - 在图例中平方而不是线条 Matlab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39952256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com