如何更改matlab colorbar缩放

问题描述 投票:6回答:2

我很难理解如何在Matlab2015b中更改我的色条范围。

默认情况下,它的范围是0到1.我设法通过使用以下方法更改标签:

    c=colorbar;
    c.Limits=[0 180] % the range that I want

问题是当我这样做时颜色不会缩放,换句话说,它将显示从0到180,但仍然使用与[0 1]相关联的颜色,这使得整个条形看起来像一种颜色。

enter image description here

我只是通过更改刻度并执行以下操作来使用另一种方法:

colorbar('Yticks',[0:10:180])

同样,颜色条仍然与0到1相关联,因此除了0之外的任何刻度都不会出现,因为第一个从10开始。

enter image description here

如何更改基于的数据?我尝试改变c.UserData但它没有做任何事情。

matlab colorbar colormap
2个回答
2
投票

从您的评论中,我看到您要做的事情。

你在右边的行设置ytick,但是你注意到这只会改变你的颜色条上的刻度的位置,但缩放保持不变。相反,尝试设置yticklabel

% Show the colorbar
c = colorbar;

% Define the desired ticks
ticks = [0:10:180];

% Sets the correct location and number of ticks
set(c, 'ytick', ticks / max(ticks));

% Set the tick labels as desired
set(c, 'yticklabel', ticks);

1
投票

可以通过以下方式实现不手动覆盖刻度规范的方法:

limits = [0,180];
c = colorbar;
set(gca,'clim',limits([1,end]))

从那里,可以根据需要手动改变或单独留下刻度。

  1. 原始比例色条
  2. 重新缩放,但保留自动刻度标签

enter image description here enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.