Effacer les filtres
Effacer les filtres

how to change colorbar's color to continuous

24 vues (au cours des 30 derniers jours)
Li Xue
Li Xue le 8 Mai 2018
Commenté : Ameer Hamza le 8 Mai 2018
Hi, I generated the following plot:
But the colorbar ticks are not corresponds to each color. For example, 2 is inside of one color. Is it possible to change the colorbar to continuous?
Also, my matrix does not have negative values. I would like to use more levels of red colors to describe my data and only one level of blue for show negative.
Here is my code:
A=readtable('data.csv');
B=table2array(A(:,2:end));
heatmap_obj=HeatMap(B,'Colormap',redbluecmap)
h=plot(heatmap_obj)
hcb=colorbar(h);
Data is attached.

Réponse acceptée

Ameer Hamza
Ameer Hamza le 8 Mai 2018
Modifié(e) : Ameer Hamza le 8 Mai 2018
This is happening because you are using matrix redbluecmap as the color map, and this matrix only contains 11 colors. Either run the code with default colormap like this
heatmap_obj=heatmap(B)
or increase the number of colors in redbluecmap.
Edit:
the final code after discussion in comment is:
A=readtable('data.csv');
B=table2array(A(:,2:end));
cmap = redbluecmap;
newCmap = imresize(cmap, [64, 3]); % original color map contain just 11 colors, this increase it to 64
newCmap = min(max(newCmap, 0), 1);
heatmap_obj=HeatMap(B,'Colormap', newCmap);
h=plot(heatmap_obj);
hcb=colorbar(h);
  6 commentaires
Li Xue
Li Xue le 8 Mai 2018
Modifié(e) : Li Xue le 8 Mai 2018
It looks great! Many thanks.
Ameer Hamza
Ameer Hamza le 8 Mai 2018
You are welcome.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by