【问题标题】:How to set the colorbar size and label in a subplot?如何在子图中设置颜色条大小和标签?
【发布时间】:2017-06-13 10:27:12
【问题描述】:

我有以下子图,并使用imagesc 命令打印图像。如何使颜色条的大小与两个图相匹配,并在颜色条旁边显示“[m]”或“[deg]”的标签(以水平对齐方式书写)?

f_prova3 = figure();
s1 = subplot(1,2,1); imagesc(DEM); axis equal; axis off;
hb1 = colorbar('location','eastoutside');
s2 = subplot(1,2,2); imagesc(slopeMap_int); colormap jet, axis equal;axis off;
hb2 = colorbar('location','eastoutside');

对不起,我似乎无法直接添加图像。感谢您的帮助

【问题讨论】:

  • @LuisMendo 我想添加更多,但我不能。 DEM 和 slopeMap_int 分别是大小为 512x512 和 508x508 像素的方阵。它们描绘了地形深度和计算坡度的图片。我不能包括那些。作为最低限度的工作示例,我已经包含了该代码。为了实现我想要的,我可以添加什么?
  • 如果您为DEMslopeMap_int 定义一个玩具示例就足够了

标签: matlab matlab-figure colorbar


【解决方案1】:

可以添加axis tight调整高度,使用标签属性调整标签:

DEM = magic(5);
slopeMap_int = magic(5);

f_prova3 = figure();
s1 = subplot(1,2,1); imagesc(DEM); axis equal; axis tight; axis off;
hb1 = colorbar('location','eastoutside');
s2 = subplot(1,2,2); imagesc(slopeMap_int); colormap jet; axis equal; axis tight; axis off;
hb2 = colorbar('location','eastoutside');

hb1.Label.String = '[m]';
hb1.Label.Rotation = 0;
hb1.Label.HorizontalAlignment = 'Left';

hb2.Label.String = '[deg]';
hb2.Label.Rotation = 0;
hb2.Label.HorizontalAlignment = 'Left';

我在 Matlab R2016a 中测试过。

【讨论】:

  • 不错!您不必替换它,只需添加axes tight。否则,您仍然会看到轴标签。
  • @EBH,谢谢,你是对的,我相应地更正了我的答案
  • @David 如果我想将标签字符串完全放在颜色条的顶部,我该怎么做? hb1.Label.Horizo​​ntalAlignment = '居中'; hb1.Label.VerticalAlignment = '顶部';不产生所需的输出
  • 尝试手动设置:hb1.Label.Position = [0 30]; 另见mathworks.com/help/matlab/ref/text-properties.html
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-21
  • 2020-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多