如何更改Matlab颜色条缩放 [英] How do I change matlab colorbar scaling
问题描述
我很难理解如何在Matlab2015b中更改颜色条的范围.
I am having a really hard time understanding how to change the range of my colorbar in Matlab2015b.
默认情况下,它的范围是0到1.我设法使用以下方法更改了标签:
By default it will range from 0 to 1. I managed to change the label by using:
c=colorbar;
c.Limits=[0 180] % the range that I want
问题是当我这样做时颜色不会缩放,换句话说,它将显示从0到180,但仍使用与[0 1]关联的颜色,这会使整个条形看起来像一种颜色.
The problem is the colors don't scale when I do that, in other words it will display from 0 to 180 but still uses the colors associated to [0 1], which makes look the the whole bar like one color.
我使用了另一种方法,只需更改刻度并做以下事情:
I used another approach by just changing the ticks and doing:
colorbar('Yticks',[0:10:180])
.
同样,颜色条仍与0到1相关联,因此第一个从10开始时,除0之外的所有刻度都不会出现.
Again, the colorbar is still associated to 0 to 1, so none of the ticks except 0 will appear as the first one starts at 10.
如何更改基于的数据?我尝试更改c.UserData
,但是它什么也没做.
How do I change the data it is based on ? I tried changing c.UserData
but it doesn't do anything.
推荐答案
从您的评论中,我了解您正在尝试做什么.
From your comment, I see what you are trying to do.
您位于设置ytick
的右边,但是正如您所注意到的,这仅会更改色标上刻度线的位置,但缩放比例保持不变.而是尝试设置yticklabel
:
You are on the right lines setting ytick
, but as you noticed this only changes the position of the ticks on your colorbar, but the scaling stays the same. Instead, try to set 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);
这篇关于如何更改Matlab颜色条缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!