matlab绘制尖角colorbar

Matlab代码

cmap = [69 117 180
    116 173 203
    171 217 233
    254 224 144
    253 174 77
    244 109 67
    215 48 39
    165 0 38]/255;
%画图的部分代码
figure
set(gcf,'outerposition',get(0,'screensize'))
ax = axes('Position',[0.2 0.2 0.6 0.6]); % pos需要自己设置位置
h = colorbar;
% colormap(ax,cmap)
map = colormap(jet);
colorbar_arrow(map,1,get(h,'position'),0.03)
xmin = -15; xmax = 25;
caxis([xmin xmax]);
% % % 绘制带尖角的colorbar
% x y
% 宽度 高度
% 尖角的长度
% 尖角的拐点
x = 0.2; y = 0.05; w = 0.6; h = 0.03;
pos = [x y w h]; % x y 宽度 高度
ax1 = axes('Position',pos);
[c,~] = size(cmap);
cdata = 2:c-1;
imagesc(cdata);
colormap(cmap(2:end-1,:));
box off
ax0 = axes('Position',get(gca,'Position'),'XAxisLocation','top','YAxisLocation','left',...
            'Color','none','XColor','k','YColor','k'); % 将坐标轴的位置换一下,换成上面和右面
set(ax1,'YTick', []);
set(ax0,'YTick', []);
set(ax0,'XTick', []);
box on
set(ax1,'XTick',0.5:c-1.5);
set(ax1,'XTicklabel',(xmin:5:xmax));
set(ax1,'FontSize',12, 'FontName','Arial');
ax1.TickLength = [h+0.005 0];
% 绘制尖角
ax3 = axes('Position',[x-w/(c-2),y,w/(c-2),h],'YAxisLocation','right');
set(ax3,'ycolor','none','xcolor','none');
set(ax3,'XTick',[]);
fc = [1 2 3];
vt = [0 0.5;1 0.04;1 0.96;];
patch('Faces',fc,'Vertices',vt,'FaceColor',cmap(1,:),'EdgeColor',[0 0 0],'linewidth',0.01);
ax4 = axes('Position',[x+w,y,w/(c-2),h],'YAxisLocation','left');
set(ax4,'ycolor','none','xcolor','none');
set(ax4,'XTick',[]);
fc = [1 2 3];
vt = [1 0.5;0 0.96;0 0.04;];
patch('Faces',fc,'Vertices',vt,'FaceColor',cmap(end,:),'EdgeColor',[0 0 0],'linewidth',0.01);


结果展示

在这里插入图片描述