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.
那这个呢:
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)
由于 MATLAB 只能打印(= 另存为图像)图形并且colorbar
不返回图形句柄,一种方法是安装http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig,然后使用:
colormap('jet');
cbar_handle = colorbar;
export_fig(cbar_handle, 'colorbar.png');
彩条.png:
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]);