Scatter plot - plot different symbols when data is negative

조회 수: 11 (최근 30일)
Jesse
Jesse 2015년 4월 28일
댓글: Jesse 2015년 4월 28일
Greetings all,
I'm trying to differentiate positive and negative data on a plot by representing it with different symbols (i.e. 'o' and 'x', wheere the 'x' would represent negative data), but I'm not having any luck with it.
Here's what I tried:
figure(4)
scatter(sigma2new_Case1,sigma1new_Case1)
while(sigma2new_Case1 < 0)
plot(sigma2new_Case1,sigma1new_Case1,'x');
end
The statement in the "while" - I tried scatter in there but it didn't make any difference - I still get a plot full of 'o's.
Obviously I'm doing something wrong, and if someone could provide suggestions that would be greatly appreciated.
Thanks! Jesse

채택된 답변

Joseph Cheng
Joseph Cheng 2015년 4월 28일
편집: Joseph Cheng 2015년 4월 28일
well what you're missing is any indexing inside your while loop to check which are less than 0 and basically comparing all of sigma2new_Casel to be <0. You can first figure out which items are <0 and then just plot each one. something like this
y=randi(10,1,20)-5;
x = 1:20;
neg = y<0;
figure,plot(x(~neg),y(~neg),'+',x(neg),y(neg),'o')
  댓글 수: 3
Joseph Cheng
Joseph Cheng 2015년 4월 28일
편집: Joseph Cheng 2015년 4월 28일
so you're looking at data for fully negative values in X and Y. such that only in quadrant 1 of +x and +y will be marked as positive? if that is the case you'll need to perform more logical operators.
y=randi(10,1,20)-5;
x = (1:20)-10;
negy = y<0;
negx = x<0;
neg = negy|negx;
figure,plot(x(~neg),y(~neg),'+',x(neg),y(neg),'o')
Where in the above code looks at which items in each array is negative and performs the logical operator (OR).
My suggestion is to look at the what is trying to be accomplished in my example. are you really trying to plot sigma2new_case1 versus signma1new_case1? in anycase why you're getting the mismatch is that you're not comparing like with like.
For instance in your example sig2 is all positives and sig1 is all negatives.. then you cannot compare the two indexes with each other. as you'll be trying to plot nothing against something.
to break it down with words in pseudo code
plot(sigma2new_Case1(index locations of positive sigma1new_Case1),sigma1new_Case1(index locations of positive sigma1new_Case1),'+', sigma2new_Case1(index locations of negative sigma1new_Case1),sigma1new_Case1(index locations of negative sigma1new_Case1),'o')
Jesse
Jesse 2015년 4월 28일
Joe,
The "or" really cleared things up. Thank you so much!
-J

댓글을 달려면 로그인하십시오.

추가 답변 (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