필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Behrad Ze
Behrad Ze 2022년 8월 28일
답변: Walter Roberson 2022년 8월 28일
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,

답변 (1개)

Walter Roberson
Walter Roberson 2022년 8월 28일
use caxis() to manually set the range of numbers that colors are mapped from

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by