【问题标题】:How to plot/save only the colorbar in Matlab?如何在 Matlab 中仅绘制/保存颜色条?
【发布时间】:2015-04-28 19:39:11
【问题描述】:

我怎样才能只绘制一个颜色条,例如在Matlab中从-1喷射到1?我需要将其另存为图像。

运行colorbar 还会在颜色条旁边绘制一个空轴。

【问题讨论】:

  • 你能把你现在的代码贴出来吗?
  • @Acorbe 在这里:colorbar。或colorbar; print mybar.

标签: matlab plot


【解决方案1】:

这个呢:

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) 

【讨论】:

  • 你是对的!我会这样做,然后用convert 修剪图像。
【解决方案2】:

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

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

颜色条.png:

【讨论】:

    【解决方案3】:

    受 bla 的启发,这是一个具有更多调整可能性的答案。 (Rep

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-26
      • 2020-09-26
      • 2020-02-20
      • 1970-01-01
      • 2015-08-22
      • 2012-01-23
      • 1970-01-01
      相关资源
      最近更新 更多