How to do combination of color in a single colorbar in a scatter plot?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Voss
il 15 Mar 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()
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Colorbar in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
