Plot in matlab with imagesc with different range colors in colorbar/colormap

2 vues (au cours des 30 derniers jours)
Hello to everybody.
I am trying to have an image plot with imagesc with different range colors. I explain myself.
The code is the following:
load Corr_matrix_IMS_All_Riordinato_Uncorrelated.txt
imagesc(Corr_matrix_IMS_All_Riordinato_Uncorrelated)
colormap(gray(4))
colorbar
caxis([-0.55 1]);
I enclose here the figure i obtain.
I need 4 colours in gray scale with the following limits [-0.55 0], [0 0.5], [0.5 0.9], [0.9 1]. Matlab makes 4 colours but just divides equally the colours range, like the picture enclosed.
I googled a lot but it was not really helpful.
I hope somebody can handle this.
Thank you very much in advance.
Best regards,
Alban Kita

Réponse acceptée

Walter Roberson
Walter Roberson le 17 Avr 2019
You need to create a color map as follows:
rows 1 to 11: 0 0 0
rows 12 to 21: 1/3 1/3 1/3
rows 22 to 29: 2/3 2/3 2/3
rows 30 to 31: 1 1 1
Each row covers a span of 0.05 in original value. So row 1 covers -.55 to -.50, row 2 covers -0.50 to -.45, row 3 covers -0.45 to -0.40, and so on. But it is okay that those are separate slots in the colormap, because they are assigned the same color.
You will also need to imagesc(YourArray, [-0.55 1])
just in case the array has slightly different contents that does not exactly match the boundaries you set out.

Plus de réponses (1)

Alban Kita
Alban Kita le 17 Avr 2019
Thank you very much Walter Roberson.
It worked perfectly.
Best regards
Alban Kita

Catégories

En savoir plus sur White dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by