How to do combination of color in a single colorbar in a scatter plot?

1 visualización (últimos 30 días)
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");

Respuesta aceptada

Voss
Voss el 15 de Mzo. de 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()

Más respuestas (0)

Categorías

Más información sobre Colorbar en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by