How can I display min and max in the colorbar?
76 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I would like to display max and min value on my colorbar.
How can I do it?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163088/image.png)
In my plot it only displays 0.01, 0.02, 0.03...
I want to display max and min also on the colorbar.
Thanks.
Risposta accettata
Azzi Abdelmalek
il 1 Mag 2016
h=colorbar
t=get(h,'Limits');
set(h,'Ticks',linspace(t(1),t(2),5)
2 Commenti
Walter Roberson
il 2 Mag 2016
You need to also set the TickLabels properties.
Could you confirm that you are using R2014b or later? It appears likely you are as Ticks was not a property of colorbars from R2014a and before.
Più risposte (1)
gwoo
il 26 Ott 2018
You can also do the following and keep the automatically selected tick marks.
hColorbar = colorbar;
set(hColorbar, 'Ticks', sort([hColorbar.Limits, hColorbar.Ticks]))
This simply adds the limits to the tick labels and sorts them in order so they don't error out.
If you want them to be the same display precision (digits shown) as the others, you can do the typical:
round(0.00532 * 1000) / 1000
Obviously change the 1000 to whatever value you need to get whatever digit you need to round off to the one's place value for the rounding function. The /1000 gets it back in the original units.
0 Commenti
Vedere anche
Categorie
Scopri di più su Colormaps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!