Can you organize scatter plot points?
이전 댓글 표시
Hi,
I would like to graph my data with the mean +/- SEM and display the data points. When I plot this, my data points are overlapping and difficult to distinguish. Rather than a random distribution/jitter, I would like my data points for same/similiar values to form nonoverlaping rows of points. Is this poissible in Matlab? Any help is greatly appreciated!
Thanks,
Dan
Example code:
subplot 133
% Plot horizontal line at 50%
yline(0.5,'k--','LineWidth',ylineLW)
hold on
% Plot data points
scatter(y1(:,1),data(:,1),'black','filled','MarkerFaceAlpha',0.5,'MarkerEdgeAlpha',0.5,'XJitter','randn')
scatter(y1(:,2),data(:,2),'red','filled','MarkerFaceAlpha',0.5,'MarkerEdgeAlpha',0.5,'XJitter','randn')
scatter(y1(:,3),data(:,3),'black','filled','MarkerFaceAlpha',0.5,'MarkerEdgeAlpha',0.5,'XJitter','randn')
scatter(y1(:,4),data(:,4),'red','filled','MarkerFaceAlpha',0.5,'MarkerEdgeAlpha',0.5,'XJitter','randn')
% Plot errorbar (SEM)
errorbar(y2(1),mData(1),SEM(1),'k_','LineWidth',errorbarLW)
errorbar(y2(2),mData(2),SEM(2),'r_','LineWidth',errorbarLW)
errorbar(y2(3),mData(3),SEM(3),'k_','LineWidth',errorbarLW)
errorbar(y2(4),mData(4),SEM(4),'r_','LineWidth',errorbarLW)
% Plot mean values
plot(y2(1),mData(1),'k_','LineWidth',plotLW,'MarkerSize',plotMS)
plot(y2(2),mData(2),'r_','LineWidth',plotLW,'MarkerSize',plotMS)
plot(y2(3),mData(3),'k_','LineWidth',plotLW,'MarkerSize',plotMS)
plot(y2(4),mData(4),'r_','LineWidth',plotLW,'MarkerSize',plotMS)
hold off
PS I attached one of my plots to help visualize the problem. Please let me know if you have any questions... thanks again!

댓글 수: 12
dpb
2021년 5월 5일
Yeah, I have questions... :)
"I would like my data points for same/similiar values to form nonoverlaping rows of points"
What does the above mean, exactly?
Plots look ok to me; what do you think is hard to distingush? Can you sketch what you think one of these should look like instead?
Dan Griffiths
2021년 5월 6일
편집: Dan Griffiths
2021년 5월 6일
Scott MacKenzie
2021년 5월 6일
It would help if you also provided the data, so your code can be excuted and tweaked a bit.
One idea... Have you tried using rand instead of randn for the XJitter property? Perhaps that will produce the non-overlapping effect you are after.
Dan Griffiths
2021년 5월 6일
dpb
2021년 5월 6일
Well, unless the x values for every point are identical, the points aren't going to be in columns. If that's what you want, replace each X vector with, say, mean(X).
I'd never noticed there being a 'jitter' propery on scatter before; don't know when that might have been introduced--or maybe it's been there "since forever" and I just never saw it. Not sure of the point/intent.
Scott MacKenzie
2021년 5월 6일
편집: Scott MacKenzie
2021년 5월 6일
OK, that's a start. Still can't execute your code, however. Please provide the script used to read the data from the file into the variables in your example code -- or just edit the example code so it can be executed.
Dan Griffiths
2021년 5월 6일
Dan Griffiths
2021년 5월 6일
dpb
2021년 5월 6일
"see a jitterless plot."
I have to say that looks far preferable to me than any of the other results. My take is that "if data overlap, they overlap" and to show them as something else is a fabrication.
But, if you want something that isn't going to be random, add a fixed delta to each point which is within some tolerance of its neighbor(s). However many are in the overlap region in y direction will be 2X the number of intervals required with 0 as [-N:N]*dx.
Dan Griffiths
2021년 5월 7일
Matt J
2021년 5월 7일
What you describe is basically the same as a histogram. Why not just use the histogram() command?
Dan Griffiths
2021년 5월 7일
채택된 답변
추가 답변 (2개)
This may be more along the lines of what you were originally looking for
load Data;
w=max( max(data,[],1) - min(data,[],1) ); %Maximum swarm width
xoffset=w; %separation between swarms
P=size(data,2);
for n=1:P
y=data(:,n);
bins=linspace(min(y),max(y),15);
[counts,~,G]=histcounts(y,bins);
sumc=sum(counts);
x=nan(size(y));
for i=1:numel(counts)
J=(G==i);
N=counts(i);
if N<2
x(J)=0;
else
x(J)=(w*N/sumc)*linspace(-0.5,+0.5,N);
end
end
x=x+n*xoffset;
h(i)=scatter(x,y,'filled');
axis equal
hold on
end
hold off
xticks((1:P)*xoffset)
xlim([xoffset/2,P*w+xoffset/2])
xticklabels({'Sham','TBI'})
Steven Lord
2021년 5월 7일
0 개 추천
When I look at your plot it looks to me an awful lot like the boxplot thumbnail in the Plots tab of the Toolstrip. You may want to investigate if that can display the information in a less cluttered approach than a simple scatter plot.
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





