Azzera filtri
Azzera filtri

how to change colorbar's color to continuous

24 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Ameer Hamza
Ameer Hamza il 8 Mag 2018
Modificato: Ameer Hamza il 8 Mag 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 Commenti
Li Xue
Li Xue il 8 Mag 2018
Modificato: Li Xue il 8 Mag 2018
It looks great! Many thanks.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Colormaps in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by