define color range in scatter plot
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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 件のコメント
Turbulence Analysis
2022 年 6 月 29 日
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()

Turbulence Analysis
2022 年 6 月 29 日
Thank you very much!!
Turbulence Analysis
2022 年 6 月 30 日
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 !!
Jonas
2022 年 6 月 30 日
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);

Turbulence Analysis
2022 年 6 月 30 日
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?
Turbulence Analysis
2022 年 6 月 30 日
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 !!
Jonas
2022 年 7 月 1 日
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
2022 年 7 月 1 日
Thank you very much, Jonas!!
その他の回答 (1 件)
KSSV
2022 年 6 月 29 日
カテゴリ
ヘルプ センター および File Exchange で Red についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
