define color range in scatter plot

18 visualizzazioni (ultimi 30 giorni)
Hi,
I have values ranging from 0 to 3000. Here, only for the values ranging between 2000 to 3000 I have to use the color palette, for rest of the values (i.e. 0 to 1000) the color should be in black..
And I am using scatter plot here.. Is it possible to define above conditions in the scatter plot..

Risposta accettata

Jonas
Jonas il 29 Giu 2022
Modificato: Jonas il 29 Giu 2022
i do not fully understand, you want to use the pallett for split to 0 to 3000, but at a certain threshold you want to use black instead?
what about values between 1000 and 2000?
x = linspace(0,3*pi,2000);
y = cos(x) + rand(1,2000);
c = linspace(1,10,length(x));
sp=scatter(x,y,[],c);
currMap=colormap();
[~,highestCDataIdx]=max(sp.CData(sp.XData<=3));
highestCDataIdx=ceil(highestCDataIdx*size(currMap,1)/numel(sp.XData)); % scale CData Index by ration of colormap elements to number of XData to map
currMap(1:highestCDataIdx,:)=0;
colormap(currMap)
you can also change values inbetween without changing the pallett
x = linspace(0,3*pi,2000);
y = cos(x) + rand(1,2000);
c = linspace(1,10,length(x));
sp=scatter(x,y,[],c);
currMap=colormap();
[~,highestCDataIdx]=max(sp.CData(sp.XData<=3));
highestCDataIdx=ceil(highestCDataIdx*size(currMap,1)/numel(sp.XData)); % scale CData Index by ration of colormap elements to number of XData to map
currMap(1:highestCDataIdx,:)=0;
colormap(currMap);
delInbetween=sp.XData<5 & sp.XData>4;
sp.XData(delInbetween)=[];
sp.YData(delInbetween)=[];
sp.CData(delInbetween)=[];
  12 Commenti
Jonas
Jonas il 1 Lug 2022
so some things to make the points in your cloud better distinctable: you can change the marker and the marker size and the coarseness of you colormap:
load('matlab.mat','x','y')
scatter(x,y,[],linspace(0,1,numel(x)),'.','SizeData',1)
colorbar;
cm=colormap('colorcube');
cm=cm(1:8:end,:);
colormap(cm)
or, if you want to use the supplied c for whatever reason
load('matlab.mat','c');
figure;
scatter(x,y,[],c,'.','SizeData',1)
colorbar;
cm=colormap('colorcube');
cm=cm(1:8:end,:);
colormap(cm)
Turbulence Analysis
Turbulence Analysis il 1 Lug 2022
Thank you very much, Jonas!!

Accedi per commentare.

Più risposte (1)

KSSV
KSSV il 29 Giu 2022
Read about clim, caxis.

Categorie

Scopri di più su Colormaps 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!

Translated by