MATLAB-重新定义YTickLabel [英] MATLAB - Redefine YTickLabel

查看:421
本文介绍了MATLAB-重新定义YTickLabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MATLAB中编辑颜色栏时遇到问题.绘制了颜色条,我想在YTickLabels上添加特定测量的单位(dB).这是通过以下命令完成的:

I have a problem with editing the colorbar in MATLAB. The colorbar is drawn and I want to add the unit (dB) for the specific measurement on YTickLabels. This is done by following commands:

cy = get(ch,'YTickLabel');  
set(ch,'YTickLabel',[]);  
set(ch,'YTickLabel',strcat(cy,{' dB'})); 

但是当我调整图的大小时,MATLAB重新定义间隔,并且输出重复两次,例如:

But when I resize the figure, MATLAB redefines the intervals, and the output is repeated twice, like:

10 dB,20 dB,30 dB,10 dB,20 dB,30 dB,而不是10 dB,20 dB,30 dB.

10 dB, 20 dB, 30 dB, 10 dB, 20 dB, 30 dB instead of 10 dB, 20 dB, 30 dB.

如何防止MATLAB重新定义其Y轴刻度,从而不会弄乱我的颜色栏?

How do I prevent MATLAB from redefining its Y axis ticks, so it doesn't mess up my colorbar?

推荐答案

为防止在调整图形大小时更改y轴刻度值,您将必须显式设置 'YLim'属性(或设置 'YLimMode'属性'manual'),以防止更改颜色栏的限制.这是一种可能的解决方案:

In order to keep the y-axis tick values from being changed when the figure is resized, you will have to either explicitly set the 'YTick' property or set the 'YTickMode' property to 'manual' (to keep it from being automatically changed). You may also have to explicitly set the 'YLim' property as well (or set the 'YLimMode' property to 'manual') to keep the limits of the color bar from changing. Here's one possible solution:

labels = get(ch,'YTickLabel');    %# Get the current labels
set(ch,'YLimMode','manual',...    %# Freeze the current limits
       'YTickMode','manual',...   %# Freeze the current tick values
       'YTickLabel',strcat(labels,{' dB'}));  %# Change the labels

在对

You can also define the tick properties when you create the color bar in your initial call to the COLORBAR function. For example, if you know you will want to have 3 tick values at 10, 20, and 30 with "dB" added to the labels, you can create the color bar in the following way:

ch = colorbar('YLim',[10 30],...                        &# The axis limits
              'YTick',[10 20 30],...                    %# The tick locations
              'YTickLabel',{'10 dB','20 dB','30 dB'});  %# The tick labels

调整图形大小时,这些限制,刻度值和刻度标签也应保持不变.

These limits, tick values, and tick labels should also remain unchanged when the figure is resized.

这篇关于MATLAB-重新定义YTickLabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆