Help getting clim (caxis) to work as I want

87 views (last 30 days)
Hello,
I am using a graph to show some lines (defined by their start and end points) each of which has a color depending on a value stored in a vector. The values in that vector can potentially vary from 0 to 1, but actually the minimum value in the dataset I am using for my tests is 0.55 approximately.
If I don't specify the limits for the colorbar it automatically adapts to the 0.55-1 range of my dataset, which is fine, but if I set it to [0 1] what it does is assigning the lowest color value to all values below 0.55, so the color scale between 0.55 and 1 doesn't change. What I want is to have that colorbar gradually varying from 0 to 1, no matter what actual range I have in my dataset.
This is the code I am using:
figure;hold on;
% Drawing the graph. startv is the vector containing three columns with the start points of each line and endv contains the end points.
% ColorVector is a vector contaning a value in the range 0-1 per line
for i=1:length(ColorVector)
patch([startv(i,1);endv(i,1)],[startv(i,2);endv(i,2)],[startv(i,3);endv(i,3)], [ColorVector(i);ColorVector(i)],'EdgeColor','interp');
end
% Adjusting the colormap and colorbar
colormap jet;
clim="Manual";
clim=[0 1];
%caxis=[0 1];
c=colorbar;
% c.LimitsMode="manual";
% map=colormap;
c.Limits=[0 1]; %kolore barraren mugak finkatu
view(3)
This is what I get:
As you can see in my commented code, I have tried several things, including setting the colormap limits (using clim since I am using Matlab 2022a, but also caxis in case clim wasn't working properly) and the colorbar limits. I have tried to follow the clim documentation and examples (https://www.mathworks.com/help/matlab/ref/clim.html?searchHighlight=clim&s_tid=srchtitle_clim_1) and they seem clear to me but I am not able to adjust the colorbar as I intend.
Thanks in advance for your help.
Julen

Accepted Answer

Walter Roberson
Walter Roberson on 22 Jul 2022
Moved: Mike Croucher on 18 Dec 2024
%caxis=[0 1];
should instead be
caxis([0 1])
  1 Comment
Julen Ibarretxe
Julen Ibarretxe on 22 Jul 2022
Moved: Mike Croucher on 18 Dec 2024
Thanks Walter, that was it.
And I had the same error with clim, which uses the same sintax as caxis.
Julen

Sign in to comment.

More Answers (0)

Categories

Find more on Color and Styling in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!