Colorbar not matching colormap

47 vues (au cours des 30 derniers jours)
Pere Garau Burguera
Pere Garau Burguera le 20 Mar 2020
Réponse apportée : darova le 20 Mar 2020
I want to do a scatter plot with points in different colors in the following way (Using Matlab 2018b).
colormap = jet(256);
v = rescale(pwdb, 1, 256);
numValues = length(pwdb);
markerColors = zeros(numValues, 3);
figure
for k = 1 : numValues
row = round(v(k));
markerColors(k, :) = colormap(row, :);
end
scatter(location(1,:), location(2,:), [], markerColors,'filled');
This works fine, the points are plotted with the right colors.
However, when I try to add the colorbar (with ), I get the following:
colorbar
What is the way to include the color red in the bar and the right values?
Thanks

Réponse acceptée

Image Analyst
Image Analyst le 20 Mar 2020
colormap is a function and you just blew it away with this line of code:
colormap = jet(256);
That overwrote the colormap function (luckily not permanently) with a 256-by-3 double array.
Try it this way
colormap(jet(256));

Plus de réponses (1)

darova
darova le 20 Mar 2020
Try to change color axis
caxis([min(markerColors(:)) max(markerColors(:))])

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by