Matlab--调整colorbar并添加title

分类: MATLAB |
画填色图时往往需要对填色的变量进行说明,一般选择对colorbar加上一条legend
常见方法有两种,第一种是加一个ylabel
ylabel(colorbar,'This is a
title','FontSize',14,'FontName','Times New
Roman','FontWeight','bold')
第二种是对colorbar设置,添加title,更适用于水平的colorbar
ch = colorbar('horiz'); %将colorbar调整为水平
set(get(ch,'title'),'string','This is a tile','position',[150
-35],'FontSize',14);%
title的位置,150代表左右,-35代表上下,可以不加position发现默认位置在colorar中间
code:
[x,y] = meshgrid([1:10],[6:15]);
c=x.*y;
figure
[C,h]=contourf(x,y,c,10);hold on;
set(h,'Color','none');
colormap jet;
set(gca,'FontSize',14,'FontName','Times New
Roman','FontWeight','bold');
% method 1
colorbar;
ylabel(colorbar,'This is a
title','FontSize',14,'FontName','Times New
Roman','FontWeight','bold')
% method 2
ch=colorbar('horiz');
set(get(ch,'title'),'string','This is a title','position',[150
-35],'FontSize',14);
后一篇:WRF的安装,从环境变量开始