Plotting multiple scatter points against yticklabel

2 ビュー (過去 30 日間)
Yuktha Andie Ravinthiran
Yuktha Andie Ravinthiran 2022 年 12 月 11 日
コメント済み: Voss 2022 年 12 月 11 日
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

採用された回答

Voss
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
  2 件のコメント
Yuktha Andie Ravinthiran
Yuktha Andie Ravinthiran 2022 年 12 月 11 日
Yes this works thank you, I fixed the other stuff with my legend etc !!
Voss
Voss 2022 年 12 月 11 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by