Plotting multiple scatter points against yticklabel
2 次查看(过去 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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!