Plotting multiple scatter points against yticklabel
조회 수: 23 (최근 30일)
이전 댓글 표시
Hi, I want to plot my mean and stnadard deviation by I can't do this if I plot against yticklabel so I tried to make 2 axis and it hasn't worked out.
I would like U1 to be next to my purple and A1 label to be next to my blue points
I could use xline but then it becomes a bit confusing as the lines go into both scatter data .
I also don't want each scatter point labelled as they are collectively 2 sets of points. (legend)

%% Figure 1
f1=figure(1);
set(f1,'color','w');
yyaxis left
set(gca,'YTickLabel', {'U1'; 'A1'});
label1 = {'U1'}
label2 = {'A1'}
yyaxis right
set(gcs,'Ytick',[]);
plot1 = scatter(U1,1,'o','color', [0.7 0 1],'markerfacecolor',[0.7 0 1],'markeredgecolor',[0.7 0 1],'MarkerFaceAlpha',0.5);
hold on
plot2 = scatter(A1,2,'o','color',"b",'markerfacecolor', "b",'markeredgecolor', "b",'MarkerFaceAlpha',0.5);
hold on
meanA = scatter(Ubar,1,'o','color','r','markerfacecolor','r','markeredgecolor','r','MarkerFaceAlpha',0.7);
meanU = scatter(Abar,2,'o','color','r','markerfacecolor','r','markeredgecolor','r','MarkerFaceAlpha',0.7);
hold on
plot([Abar Abar],[1.5 3],'r','LineStyle','--','LineWidth',1);
plot([Ubar Ubar],[0 1.5],'r','LineStyle','--','LineWidth',1);
%Confidence intervals for means
plot([0.0219 0.0219],[1.5 3],'r','LineStyle','--','LineWidth',0.5);
plot([1.0113 1.0113],[1.5 3],'r','LineStyle','--','LineWidth',0.5);
plot([0.1305 0.1305],[0 1.5],'r','LineStyle','--','LineWidth',0.5);
plot([0.2685 0.2685],[0 1.5],'r','LineStyle','--','LineWidth',0.5);
%use error bars to plot std
errorbar([Ubar],[1],Usigma,'horizontal','LineWidth',1)
errorbar([ Abar],[2],Asigma,'horizontal','LineWidth',1)
ylim([0 3]);
xlabel('OD');
hold off
댓글 수: 0
채택된 답변
Voss
2022년 12월 11일
If I understand what you want to do, it doesn't seem like you need two axes.
See below for how to set the YTickLabels correctly.
What exactly do you want in the legend?
% first, I generate some random values for your variables:
Abar = 0.53;
Ubar = 0.2;
Asigma = 0.1;
Usigma = 0.05;
A1 = Abar+Asigma*randn(1,10); % whatever
U1 = Ubar+Usigma*randn(1,10);
%% Figure 1
f1=figure(1);
set(f1,'color','w');
% yyaxis left
% set(gca, 'YTickLabel', {'U1'; 'A1'});
% label1 = {'U1'}
% label2 = {'A1'}
% yyaxis right
% set(gcs,'Ytick',[]);
plot1 = scatter(U1,1,'o','color', [0.7 0 1],'markerfacecolor',[0.7 0 1],'markeredgecolor',[0.7 0 1],'MarkerFaceAlpha',0.5);
hold on
plot2 = scatter(A1,2,'o','color',"b",'markerfacecolor', "b",'markeredgecolor', "b",'MarkerFaceAlpha',0.5);
% hold on
meanA = scatter(Ubar,1,'o','color','r','markerfacecolor','r','markeredgecolor','r','MarkerFaceAlpha',0.7);
meanU = scatter(Abar,2,'o','color','r','markerfacecolor','r','markeredgecolor','r','MarkerFaceAlpha',0.7);
% hold on
plot([Abar Abar],[1.5 3],'r','LineStyle','--','LineWidth',1.5);
plot([Ubar Ubar],[0 1.5],'r','LineStyle','--','LineWidth',1.5);
%Confidence intervals for means
plot([0.0219 0.0219],[1.5 3],'r','LineStyle','--','LineWidth',0.5);
plot([1.0113 1.0113],[1.5 3],'r','LineStyle','--','LineWidth',0.5);
plot([0.1305 0.1305],[0 1.5],'r','LineStyle','--','LineWidth',0.5);
plot([0.2685 0.2685],[0 1.5],'r','LineStyle','--','LineWidth',0.5);
%use error bars to plot std
errorbar([Ubar],[1],Usigma,'horizontal','LineWidth',1)
errorbar([ Abar],[2],Asigma,'horizontal','LineWidth',1)
% ylim([0 3]);
set(gca, 'YLim', [0 3], 'YTick', [1 2], 'YTickLabel', {'U1'; 'A1'});
xlabel('OD');
hold off
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
