Repeating values on colorbar
Ältere Kommentare anzeigen
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 Kommentare
KSSV
am 16 Dez. 2019
Check the values obtained in this line:
hcolorBar.TickLabels = round((1/17)*hcolorBar.Ticks,2)
Sunil S Hosakoti
am 21 Dez. 2019
Bearbeitet: Sunil S Hosakoti
am 1 Jan. 2020
Image Analyst
am 1 Jan. 2020
Bearbeitet: Image Analyst
am 1 Jan. 2020
What are the values your image has? What is the min and what is the max gray level? What is ha? How did you display the image? This works
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')
Sunil S Hosakoti
am 6 Jan. 2020
Adam
am 7 Jan. 2020
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.
Akzeptierte Antwort
Weitere Antworten (1)
Ruger28
am 6 Jan. 2020
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 Kommentare
Ruger28
am 6 Jan. 2020
Which version of MATLAB are you using?
Sunil S Hosakoti
am 7 Jan. 2020
Bearbeitet: Sunil S Hosakoti
am 7 Jan. 2020
Ruger28
am 7 Jan. 2020
Strange. It worked for me on 2018b.
Kategorien
Mehr zu Data Distribution Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
