Scatterplot with condition on another matrix

1 次查看(过去 30 天)
Hi I have 2 matrices A and B that are 1x98 that I want to plot using scatterplot. I also have the third matrix C that is used to separate the data.
So if A<=C, the dots should appear blue, and if A>C, the dots should appear black.
How do I set that up, and what the code should look like?
Thanks. I need this as soon as possible.
  6 个评论
dpb
dpb 2019-9-10
Well, we only know what you tell us...we don't know the magic correlations. :)
See updated Answer...
dpb
dpb 2019-9-10
"but it does not seem like it separates the 2 conditions"
Because the syntax is incorrect for the if test. You've written the two variables w/o the subscript which returns a logical vector of the same size as they. if is true iff all elements of the condition are true; see the documenation for IF for details.
Also, even with that corrected, you've done the same thing in the argument to scatter; each time you call it, it will do the full vectors with the particular color...excepting since only the false case will ever actually execute, your code draws the same scatter plot over and over length(index_of_max_data) times, always with the same result.
See the previous Answer for "the MATLAB way"

请先登录,再进行评论。

采纳的回答

dpb
dpb 2019-9-9
编辑:dpb 2019-9-10
clr=[0 0 1; 0 0 0]; % blue, black RGB triplets
c=clr((A>C)+1,:); % set which based on lookup
scatter(A,B,[],c,'filled')
W/ revised .mat file and clarification of "who's who in the zoo", then the above does what Q? asks with
A=index_of_max_data.'; B=BP1_at_max_data.';C=S_G2_transition_point_data.';
If you instead want red instead of blue, fix up the clr rgb triplet to match desired color(s).
  2 个评论
Chi Pham
Chi Pham 2019-9-10
figure
clr=[0 0 1 ; 0 0 0]; % blue, black RGB triplets
c=clr((index_of_CDK2drop_escape<=S_end_escape)+1,:); % set which based on lookup
scatter(index_of_CDK2drop_escape*10/60,BP1_at_CDK2drop_escape,[],c)
legend('CDK2 drop before S/G2 transition', 'CDK2 drop before S/G2 transition');
xlabel('Absolute time (hr)')
ylabel('BP1 cumsum at CDK2 drop')
Thank you for your help. I have an additional quick question though. Why does my legend only have one type of data point? It reports that Ignoring extra legend entries.
dpb
dpb 2019-9-10
编辑:dpb 2019-9-11
Ah! You didn't specify two legends! :)
"Why?" is because drawn this way you have only a single scatter() object set of points and legend() is hooked intimately with the number of objects drawn onto the axes. Only one and it'll only add one.
Two ways to fix -- first would be to select the two sections of the data and scatter() them separately instead of together. That takes extra logic to build the selection and two calls to scatter() initially.
The other is to create a set of dummy scatter() objects to label from the colors array as
...
hold on
hS=arrayfun(@(i) scatter(nan,nan,[],clr(i,:),'filled'),1:size(clr,1));
hL=legend(hS,'A','B','Location','northwest');
The above after you've done the previous plotting adds two scatter() objects that are invisible but match the two (or howerver many you define) colors and marker type as targets for the subsequent call to legend that uses those two object handles.
Your choice as to which way to do it...

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by