show regular intervals in the colourbar
Show older comments
I would like to have the colourbar displaying values for regular intervals: that is, I would like to have the colourbars displaying both extremes (max and min) and a fixed number of intermediate values (intervals), automatically.
1 Comment
Francesco Marchione
on 24 Sep 2021
Answers (1)
Vedant Shah
on 5 Mar 2025
To calculate a fixed number of evenly distributed values between the minimum and maximum, including the endpoints, the “linspace” function can be used. This function generates tick values that can be applied to the colorbar, ensuring visibility of both extremes and the specified number of intermediate intervals.
For detailed information about the “linspace” function, following documentation can be referred:
To implement the desired results, replace the existing line of code:
set(hcb, 'Ticks', sort([hcb.Limits, hcb.Ticks]))
with:
numIntervals = 5;
minValue = min(Zm(:));
maxValue = max(Zm(:));
tickValues = linspace(minValue, maxValue, numIntervals + 1);
set(hcb, 'Ticks', tickValues);
This modification ensures the output displays the required intervals effectively.
Categories
Find more on Color and Styling in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!