How to do combination of color in a single colorbar in a scatter plot?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have one data set of 4964 values "s" varible with latitude and longitude. I want to plot all the positive values with red color (gradually shaded color) using "BREWERMAP Function" link provided. Zero Values in Green color and negative values in blue (Not shaded fix color). Tried many things couldn't able get a desired output. The figure should have a single colorbar. Tried using different axis, but that generate 3 colorbar. Any help will be appreciated.
Code
scatter(lon,lat,6,s,"filled");
0 Kommentare
Akzeptierte Antwort
Voss
am 15 Mär. 2025
Maybe something like this.
load Data
reds = brewermap([],'Reds');
green = [0 1 0];
blue = [0 0 1];
smax = max(s(:));
nr = size(reds,1);
ng = 2;
nb = floor(nr/25);
c = zeros(numel(s),3);
idx = s > 0;
c(idx,:) = reds(ceil(s(idx)*nr/smax),:);
idx = s == 0;
c(idx,:) = repmat(green,nnz(idx),1);
idx = s < 0;
c(idx,:) = repmat(blue,nnz(idx),1);
scatter(lon,lat,6,c,"filled");
colormap([repelem([blue; green],[nb,ng],1); reds])
clim([-(nb+ng/2)/(nr+ng/2),1]*smax)
colorbar()
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Colorbar finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!