Clear Filters
Clear Filters

How to set the colors and numbers of a colorbar to special values

1 view (last 30 days)
Dear Experts,
I am using matlab to plot a series of surfaces with different maximum and minimum Z values, I want to set the maximum and minimum of all the plots to specific numbers and specific colors, to be able to compare the surfaces easily. For example, set my limits to the range (-7 to -27),and set its colors(blue -7, white 0, and red 27) for all plots. Some of my plots may not reach to these limits, However, I also want to apply this rule for them, therefore matlab selects the color automatically based on the color rules mentionaed above (for example the attached sample file can not reach to the limitations).I am using the code as below
csvfiles = dir('*.csv');
for file = csvfiles'
sample=readmatrix(file.name);
x=sample(1,2:end);
y=sample(2:end,1);
dataSample=sample(2:end,2:end);
figure();
graph=surf(x,y,dataSample);
xlim([400 4000])
ylim([400 4000])
zlim([-7 27])
set(graph,'LineStyle','none');
title(file.name)
colormap('turbo');
colorbar();
view(2);
end
Any help in this regard will be highly appreciated.
Best Regards,

Answers (1)

Walter Roberson
Walter Roberson on 28 Aug 2022
use caxis() to manually set the range of numbers that colors are mapped from

Categories

Find more on Colormaps in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!