define color range in scatter plot
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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..
채택된 답변
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
Thanks, Jonas..
This is what I am exactly looking at..
Actually,the values between 0 to 2000 should be in black and palette for the rest i.e. 2000 to 3000
so the full pallett for the rest or just parts of the palette?
or are you already happy with the given code?
clear
x = linspace(0,3000,20000);
y = 3*sin(2*pi*1/1000*x)+rand(1,20000);
c = linspace(1,10,length(x));
figure;
scatter(x,y,[],c);

figure;
sp=scatter(x,y,[],c);
currMap=colormap();
[~,highestCDataIdx]=max(sp.CData(sp.XData<=2000));
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);

figure;
y=y(x>2000);
x=x(x>2000);
c = linspace(1,10,length(x));
scatter(x,y,[],c);
xlim([0 3000])
linkaxes()

Thank you very much!!
Jonas,
Is there a way to fix particular color rather than a gradient , lets say
for 0 to 2 - green;
2 to 4 - red;
4 to 6 - yellow
something like this
Thanks !!
you can give each point its inidividual color, e.g.
clear
x = linspace(0,3,1000);
y = 3*sin(2*pi*1*x)+rand(1,1000);
c=zeros(numel(x),3);
firstColIdx=x<=1;
secColIdx=x<=2 & x>1;
thirdColIdx=x<=3 & x>2;
firstColor=[1 0.5 0];
secondColor=[0.5 0 0.5];
thirdColor=[0 1 0];
c(firstColIdx,:)=repmat(firstColor,[sum(firstColIdx),1]);
c(secColIdx,:)=repmat(secondColor,[sum(secColIdx),1]);
c(thirdColIdx,:)=repmat(thirdColor,[sum(thirdColIdx),1]);
figure;
scatter(x,y,[],c);

Jonas, actually in my case the varible c is not defined based on x, its rather different as shown in the herewith attachment..
Jonas
2022년 6월 30일
i got a matrix with 4 columns. how to process this, how can i see what you want?
if you plot the 4 lines only with plot(yourMatrix), then your x is 1:size(yourMatrix,1)
Right now actually I am plotting like this.
As you can see I coloring based on entries in the matrix c. Since the selected colormap adopts gradient scale sometimes it is very difficult to differentiate..
figure ()
ax = gca;
scatter(x(:,1),y(:,1),0.2,c(:,1))
ylim ([0 3500]);
xlim ([0 1]);
%grid on
set(gca,'TickLabelInterpreter','latex')
set(gca, 'FontSize', 12)
title(sprintf("${Y=%3dmm}$",h),'FontSize',15,'Color','black','Interpreter','latex');
width=400;
height=300;
ax.LineWidth = 2;
set(gcf,'position',[x0,y0,width,height])
colormap (flipud(colorcube))
c2 = colorbar('FontSize',12,'TickLabelInterpreter', 'latex');
caxis ([-10 35]);
Jonas
2022년 6월 30일
and how is the provided matrix connected to your code? i neither have your x, y and c nor does the provided 4 column matrix occur in your code
so you use the colormap colorcube which i do not have and how do you want to see the given plot?
Ah, Sorry.
I dont know why my previous attachment does not contains the x y c. You can find the same in this new attachment..
Actually I dont have any restriction with using colorcube, All I am looking for is colormap without gradient apparently colorcube is not.. So I am looking for another options..
The one you showed this morning is really promising, but I am having some while using my data !!
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)

Thank you very much, Jonas!!
추가 답변 (1개)
KSSV
2022년 6월 29일
0 개 추천
카테고리
도움말 센터 및 File Exchange에서 Red에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
