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);


结果展示

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值