필터 지우기
필터 지우기

Why is my diverging colormap not centered as expected?

조회 수: 8 (최근 30일)
Austin M. Weber
Austin M. Weber 2024년 3월 13일
편집: Austin M. Weber 2024년 3월 13일
I want to plot a heatmap of some data using a diverging colormap from the crameri function (File Exchange). However, the colormap is not centering about the specified pivot value:
load data.mat
figure(1)
h1 = heatmap(data);
vik = crameri('vik','pivot',0);
colormap(gca,vik)
clim(gca,[-1,1])
By setting the pivot value to 0 the colormap should be ordered like this:
What is the issue?
  댓글 수: 2
Voss
Voss 2024년 3월 13일
In the future, please refrain from uploading File Exchange files to Answers (because File Exchange requires a MathWorks login to download files but Answers does not). Linking to the relevant File Exchange submission is sufficient. I've removed crameri.m from your question.
Austin M. Weber
Austin M. Weber 2024년 3월 13일
편집: Austin M. Weber 2024년 3월 13일
@Voss, That makes sense. I removed the colormap .mat file as well because it was also from the File Exchange submission.

댓글을 달려면 로그인하십시오.

채택된 답변

DGM
DGM 2024년 3월 13일
편집: DGM 2024년 3월 13일
The problem is caused by when you call crameri(). Remember that a color table is just an ordered progression of color tuples. By itself, it doesn't carry any information about the values that it's being used to represent. So the pivot value alone is meaningless. It needs to be taken in relationship to some other limiting values in order to describe where white is with respect to the ends of the table. When you explicitly specify a pivot value, it's taken in relation to the current clim values at that moment. Since the default values for clim (i.e. on a fresh figure) are [0 1], that makes your colortable asymmetric.
If you want your table to be centered and diverging, you can either explicitly center your clim values on the intended pivot prior to calling crameri()
load data.mat
h1 = heatmap(data);
caxis(gca,[-1,1])
vik = crameri('vik','pivot',0);
colormap(gca,vik)
... or alternatively, you can simply not specify the pivot value. By default, crameri() will produce the table centered regardless of whatever the current clim values are.
load data.mat
h1 = heatmap(data);
vik = crameri('vik');
colormap(gca,vik)
caxis(gca,[-1,1])
  댓글 수: 1
Austin M. Weber
Austin M. Weber 2024년 3월 13일
@DGM, Thank you for the explanation. Makes sense, and the colormap is now working as expected!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by