필터 지우기
필터 지우기

Repeating values on colorbar

조회 수: 5 (최근 30일)
Sunil S Hosakoti
Sunil S Hosakoti 2019년 12월 16일
댓글: Sunil S Hosakoti 2020년 2월 6일
I have set a colobar for an experiment with a user defined limit for it, but i dont know why the colorbar is repeating the values cyclically. This is the part of the code that generates colorbar.
limColorBar = 2.0;
colormap(ha,'hot');
caxis([0,limColorBar])
hcolorBar = colorbar(ha); hcolorBar.LimitsMode = 'manual';
hcolorBar.Limits = [0,limColorBar];
ha.CLim = [0,limColorBar];
hcolorBar.TickLabels = round((1/17)*hcolorBar.Ticks,2); %scalefactor 1/17 for 1.6mag; 4/83 for 2.5mag
xlabel(hcolorBar,'mm/min')
Please help me rectify this.
Thank you.
  댓글 수: 5
Sunil S Hosakoti
Sunil S Hosakoti 2020년 1월 6일
The coloarbar looks perfectly fine whe window size is small but when the window is maximised the values repeat. I have attached the snipped figures.
Any idea why this happens?Capture2.JPG
Adam
Adam 2020년 1월 7일
When you resize a window the number of ticks generally changes so your number of tick labels may well become insufficient for the number of ticks. When this happens it repeats the labels you have given it for the extra ticks which do not have a label.
To deal with this you would likely have to add some code that responds to a figure resize event or simply choose how many ticks you want and hard code them, then create your tick labels from them and then when the window resizes it will not recalculate ticks.

댓글을 달려면 로그인하십시오.

채택된 답변

Ganesh Regoti
Ganesh Regoti 2020년 1월 29일
According to the doc, Tick mark labels, specified as a cell array of character vectors, a string array, a numeric array, a character vector, or a categorical array. By default, the colorbar labels the tick marks with numeric values. If you specify labels and do not specify enough labels for all the tick marks, then MATLAB® cycles through the labels.
Below is one workaround
close all; clc;
indexedImage = imread('cameraman.tif');
% Make it go from 0 - 2:
indexedImage = 2 * mat2gray(indexedImage);
imshow(indexedImage);
limColorBar = 2.0;
colormap('hot');
caxis([0,limColorBar])
hcolorBar = colorbar();
hcolorBar.LimitsMode = 'manual';
hcolorBar.Limits = [0,limColorBar];
temp = hcolorBar.TickLabels;
hcolorBar.Ticks = [str2double(temp(1)) str2double(temp(2)) str2double(temp(3)) str2double(temp(4)) str2double(temp(5))];
hcolorBar.TickLabels = round((1/17)*hcolorBar.Ticks,2); %scalefactor 1/17 for 1.6mag; 4/83 for 2.5mag
Another workaround
close all; clc;
indexedImage = imread('cameraman.tif');
% Make it go from 0 - 2:
indexedImage = 2 * mat2gray(indexedImage);
imshow(indexedImage);
limColorBar = 2;
colormap('hot');
caxis([0,limColorBar])
hcolorBar = colorbar();
hcolorBar.LimitsMode = 'manual';
hcolorBar.Limits = [0,limColorBar];
hcolorBar.Ticks = linspace(0,limColorBar,5); %This depends on limcolorbar value
hcolorBar.TickLabels = round((1/17)*hcolorBar.Ticks,2); %scalefactor 1/17 for 1.6mag; 4/83 for 2.5mag
xlabel(hcolorBar, 'mm/min') ;
Hope this helps!
  댓글 수: 1
Sunil S Hosakoti
Sunil S Hosakoti 2020년 2월 6일
It works, Thanks a lot.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ruger28
Ruger28 2020년 1월 6일
Using the example given by Image Analyst, I commented out the Limits lines of code, and it works as intended. Give that a try.
indexedImage = imread('cameraman.tif');
% Make it go from 0 - 2:
indexedImage = 2 * mat2gray(indexedImage);
imshow(indexedImage);
limColorBar = 2.0;
colormap('hot');
caxis([0,limColorBar])
hcolorBar = colorbar();
% hcolorBar.LimitsMode = 'manual';
% hcolorBar.Limits = [0,limColorBar];
hcolorBar.TickLabels
hcolorBar.TickLabels = round((1/17)*hcolorBar.Ticks,2) %scalefactor 1/17 for 1.6mag; 4/83 for 2.5mag
xlabel(hcolorBar, 'mm/min')
  댓글 수: 3
Sunil S Hosakoti
Sunil S Hosakoti 2020년 1월 7일
편집: Sunil S Hosakoti 2020년 1월 7일
The same thing happens, the values repeat when the window is maximised.
The version i use is 2019a.
Ruger28
Ruger28 2020년 1월 7일
Strange. It worked for me on 2018b.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by