4

How can I plot only a color bar, e.g. jet from -1 to 1, in Matlab? I need to save it as an image.

Running colorbar also plots an empty axis next to the color bar.

4

3 回答 3

7

那这个呢:

colorbar
axis off

编辑 :

如果您想完全控制颜色条的宽度和位置,则可以执行以下操作:

fig1=figure;
left=100; bottom=100 ; width=20 ; height=500;
pos=[left bottom width height];
axis off
colorbar([0.1 0.1  0.7  0.8]);
set(fig1,'OuterPosition',pos) 

在此处输入图像描述

于 2013-05-26T21:30:02.247 回答
3

由于 MATLAB 只能打印(= 另存为图像)图形并且colorbar不返回图形句柄,一种方法是安装http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig,然后使用:

colormap('jet');
cbar_handle = colorbar;
export_fig(cbar_handle, 'colorbar.png');

彩条.png:

在此处输入图像描述

于 2013-05-26T21:11:55.100 回答
2

Inspired by bla, here is an answer with more adjusting possibilities. (Rep<50 means no comments possible. sry!)

fig1=figure;
axis off
colormap(gray(100));
caxis([-1 1]);
h = colorbar([0.1 0.1  0.8  0.7],...
  'location','Southoutside',...
  'XTick',[-1 -0.5 0 0.5 1]);
set(h,'OuterPosition',[0.1 0.1 0.8 0.8]);

Grey Colorbar from -1 to 1

于 2015-04-28T11:39:11.353 回答