Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Behrad Ze
Behrad Ze am 28 Aug. 2022
Beantwortet: Walter Roberson am 28 Aug. 2022
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,

Antworten (1)

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

Kategorien

Mehr zu Colormaps finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by